diff --git a/django/views/i18n.py b/django/views/i18n.py
index 00ef224..26022fa 100644
a
|
b
|
|
1 | 1 | import os |
| 2 | import re |
2 | 3 | import gettext as gettext_module |
3 | 4 | |
4 | 5 | from django import http |
… |
… |
def set_language(request):
|
24 | 25 | next = request.REQUEST.get('next', None) |
25 | 26 | if not next: |
26 | 27 | next = request.META.get('HTTP_REFERER', None) |
| 28 | if next and not re.match("^https?://%s/" % re.escape(request.get_host()), next): |
| 29 | next = None |
27 | 30 | if not next: |
28 | 31 | next = '/' |
29 | 32 | response = http.HttpResponseRedirect(next) |
diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py
index 601df6d..b3014dd 100644
a
|
b
|
class I18NTests(TestCase):
|
25 | 25 | self.assertRedirects(response, 'http://testserver/views/') |
26 | 26 | self.assertEqual(self.client.session['django_language'], lang_code) |
27 | 27 | |
| 28 | def test_setlang_nonext(self): |
| 29 | """Test setlang redirection when next variable is not set""" |
| 30 | response = self.client.post('/views/i18n/setlang/', {'language': 'fr'}) |
| 31 | self.assertRedirects(response, 'http://testserver/') |
| 32 | |
| 33 | response = self.client.post('/views/i18n/setlang/', {'language': 'fr'}, |
| 34 | HTTP_REFERER='http://testserver/views/') |
| 35 | self.assertRedirects(response, 'http://testserver/views/') |
| 36 | |
| 37 | response = self.client.post('/views/i18n/setlang/', {'language': 'fr'}, |
| 38 | HTTP_REFERER='https://www.evil.org/') |
| 39 | self.assertRedirects(response, 'http://testserver/') |
| 40 | |
28 | 41 | def test_setlang_reversal(self): |
29 | 42 | self.assertEqual(reverse('set_language'), '/views/i18n/setlang/') |
30 | 43 | |
diff --git a/tests/urls.py b/tests/urls.py
index 4f37ab5..b76fd8c 100644
a
|
b
|
|
1 | 1 | from django.conf.urls import patterns, include |
2 | 2 | |
3 | 3 | urlpatterns = patterns('', |
| 4 | (r'^$', 'regressiontests.views.views.index_page'), |
| 5 | |
4 | 6 | # test_client modeltest urls |
5 | 7 | (r'^test_client/', include('modeltests.test_client.urls')), |
6 | 8 | (r'^test_client_regress/', include('regressiontests.test_client_regress.urls')), |