Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Probably better URLpattern #1418

Closed
wants to merge 4 commits into from

3 participants

@neoascetic

with unicode characters support

@digi604
Collaborator

please merge again.

@digi604
Collaborator

tests fail.

@neoascetic neoascetic closed this
@coveralls

Coverage Status

Changes Unknown when pulling de29468 on neoascetic:upstream/better_urlpattern into ** on divio:develop**.

@yakky yakky referenced this pull request from a commit in yakky/django-cms
@yakky yakky Forward port unicode path support in PR #1418 by @neoascetic 6bc8ed2
@yakky yakky referenced this pull request from a commit in yakky/django-cms
@yakky yakky Add tests for unicode paths #1418 098a165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 14 deletions.
  1. +3 −5 cms/urls.py
  2. +9 −9 cms/utils/urlutils.py
View
8 cms/urls.py
@@ -4,10 +4,8 @@
from django.conf import settings
from django.conf.urls.defaults import url, patterns
-if settings.APPEND_SLASH:
- reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$', details, name='pages-details-by-slug')
-else:
- reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)$', details, name='pages-details-by-slug')
+reg_re = r'(?u)^(?P<slug>[-.//\w]+)%s$' % (settings.APPEND_SLASH and '/' or '')
+reg = url(reg_re, details, name='pages-details-by-slug')
urlpatterns = [
# Public pages
@@ -22,4 +20,4 @@
from cms.appresolver import get_app_patterns
urlpatterns += get_app_patterns()
-urlpatterns = patterns('', *urlpatterns)
+urlpatterns = patterns('', *urlpatterns)
View
18 cms/utils/urlutils.py
@@ -4,11 +4,11 @@
import re
# checks validity of absolute / relative url
-any_path_re = re.compile('^/?[a-zA-Z0-9_.-]+(/[a-zA-Z0-9_.-]+)*/?$')
+any_path_re = re.compile('(?u)^/?[\w.-]+(/[\w.-]+)*/?$')
def levelize_path(path):
"""Splits given path to list of paths removing latest level in each step.
-
+
>>> path = '/application/item/new'
>>> levelize_path(path)
['/application/item/new', '/application/item', '/application']
@@ -23,26 +23,26 @@ def levelize_path(path):
def urljoin(*segments):
"""Joins url segments together and appends trailing slash if required.
-
+
>>> urljoin('a', 'b', 'c')
u'a/b/c/'
-
+
>>> urljoin('a', '//b//', 'c')
u'a/b/c/'
-
+
>>> urljoin('/a', '/b/', '/c/')
u'/a/b/c/'
-
+
>>> urljoin('/a', '')
u'/a/'
"""
cleaned_segments = map(lambda segment: unicode(segment).strip("/"), segments)
nonempty_segments = filter(lambda segment: segment > "", cleaned_segments)
url = ("/").join(nonempty_segments)
-
+
if segments[0].startswith("/") and not url.startswith("/"):
url = "/" + url
-
+
if settings.APPEND_SLASH and not url.endswith("/"):
url += "/"
return url
@@ -58,4 +58,4 @@ def is_media_request(request):
return True
else:
return True
- return False
+ return False
Something went wrong with that request. Please try again.