Permalink
Browse files

Trailing slash is now optional in LocaleMiddleware for supporting red…

…irect of /lang to /lang/
  • Loading branch information...
1 parent 7d26b48 commit 8e9d61b2b871ab6413b7311bbaaf65ac43481a91 @brocaar committed Feb 8, 2012
Showing with 22 additions and 2 deletions.
  1. +1 −0 README.rst
  2. +1 −1 i18nurls/middleware.py
  3. +1 −1 i18nurls/tests/base.py
  4. +14 −0 i18nurls/tests/url_tests.py
  5. +5 −0 i18nurls/tests/urls.py
View
@@ -100,6 +100,7 @@ v0.7 (development)
* ``{% language %}`` template-tag implemented (thanks to Harro van der Klauw).
* ``LocaleMiddleware`` class is not patched anymore (Issue #3).
* ``i18n_patterns`` is not patched anymore.
+* Trailing slash is now optional in ``LocaleMiddleware`` regex.
v0.6.1
~~~~~~
View
@@ -10,7 +10,7 @@
from i18nurls.urlresolvers import LocaleRegexURLResolver
-language_code_prefix_re = re.compile(r'^/([\w-]+)/')
+language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
class LocaleMiddleware(DjangoLocaleMiddleware):
View
@@ -23,10 +23,10 @@ def setUp(self):
)
self._update_setting('MIDDLEWARE_CLASSES', (
+ 'i18nurls.middleware.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
- 'i18nurls.middleware.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
))
@@ -40,6 +40,20 @@ def test_namespace(self):
class RedirectTest(BaseTestCase):
+ def test_trailing_slash_redirect_en(self):
+ response = self.client.get('/en', HTTP_ACCEPT_LANGUAGE='nl')
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response.has_header('location'), True)
+ self.assertEqual(
+ response['location'], 'http://testserver/en/')
+
+ def test_trailing_slash_redirect_nl(self):
+ response = self.client.get('/nl', HTTP_ACCEPT_LANGUAGE='en')
+ self.assertEqual(response.status_code, 301)
+ self.assertEqual(response.has_header('location'), True)
+ self.assertEqual(
+ response['location'], 'http://testserver/nl/')
+
def test_en_redirect(self):
response = self.client.get(
'/users/register/', HTTP_ACCEPT_LANGUAGE='en')
View
@@ -18,6 +18,11 @@
)
urlpatterns += i18n_patterns('',
+ url(
+ r'^$',
+ TemplateView.as_view(template_name='i18nurls/dummy.html'),
+ name='root'
+ ),
url(
r'^prefixed/$',
TemplateView.as_view(template_name='i18nurls/dummy.html'),

0 comments on commit 8e9d61b

Please sign in to comment.