Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #4772 -- Fixed reverse URL creation to work with non-ASCII argu…

…ments.

Also included a test for non-ASCII strings in URL patterns, although that
already worked correctly.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5630 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8c85ddf306e6d707e4bd521e7708509a3fb29bf1 1 parent fad7247
Malcolm Tredinnick malcolmt authored
12 django/core/urlresolvers.py
View
@@ -9,7 +9,7 @@
from django.http import Http404
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
-from django.utils.encoding import iri_to_uri
+from django.utils.encoding import iri_to_uri, force_unicode
from django.utils.functional import memoize
import re
@@ -101,7 +101,7 @@ def __call__(self, match_obj):
# First we need to figure out whether it's a named or unnamed group.
#
grouped = match_obj.group(1)
- m = re.search(r'^\?P<(\w+)>(.*?)$', grouped)
+ m = re.search(r'^\?P<(\w+)>(.*?)$', grouped, re.UNICODE)
if m: # If this was a named group...
# m.group(1) is the name of the group
# m.group(2) is the regex.
@@ -127,9 +127,9 @@ def __call__(self, match_obj):
test_regex = grouped
# Note we're using re.match here on purpose because the start of
# to string needs to match.
- if not re.match(test_regex + '$', str(value)): # TODO: Unicode?
+ if not re.match(test_regex + '$', force_unicode(value), re.UNICODE):
raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex))
- return str(value) # TODO: Unicode?
+ return force_unicode(value)
class RegexURLPattern(object):
def __init__(self, regex, callback, default_args=None, name=None):
@@ -137,7 +137,7 @@ def __init__(self, regex, callback, default_args=None, name=None):
# callback is either a string like 'foo.views.news.stories.story_detail'
# which represents the path to a module and a view function name, or a
# callable object (view).
- self.regex = re.compile(regex)
+ self.regex = re.compile(regex, re.UNICODE)
if callable(callback):
self._callback = callback
else:
@@ -201,7 +201,7 @@ class RegexURLResolver(object):
def __init__(self, regex, urlconf_name, default_kwargs=None):
# regex is a string representing a regular expression.
# urlconf_name is a string representing the module containing urlconfs.
- self.regex = re.compile(regex)
+ self.regex = re.compile(regex, re.UNICODE)
self.urlconf_name = urlconf_name
self.callback = None
self.default_kwargs = default_kwargs or {}
4 django/template/__init__.py
View
@@ -512,7 +512,7 @@ def value(self):
)?
)""" % {
'str': r"""[^"\\]*(?:\\.[^"\\]*)*""",
- 'var_chars': "A-Za-z0-9\_\." ,
+ 'var_chars': "\w\." ,
'filter_sep': re.escape(FILTER_SEPARATOR),
'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR),
'i18n_open' : re.escape("_("),
@@ -520,7 +520,7 @@ def value(self):
}
filter_raw_string = filter_raw_string.replace("\n", "").replace(" ", "")
-filter_re = re.compile(filter_raw_string)
+filter_re = re.compile(filter_raw_string, re.UNICODE)
class FilterExpression(object):
"""
3  tests/regressiontests/templates/tests.py
View
@@ -735,7 +735,8 @@ def test_templates(self):
'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
- 'url05' : (u'{% url метка_оператора 1 %}', {}, '/url_tag/unicode/1/'),
+ 'url05' : (u'{% url метка_оператора v %}', {'v': u'Ω'},
+ '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'),
# Failures
'url-fail01' : ('{% url %}', {}, template.TemplateSyntaxError),
4 tests/regressiontests/templates/urls.py
View
@@ -9,5 +9,7 @@
(r'^client/(\d+)/$', views.client),
(r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action),
url(r'^named-client/(\d+)/$', views.client, name="named.client"),
- url(r'^unicode/(\d+)/$', views.client, name=u"метка_оператора"),
+
+ # Unicode strings are permitted everywhere.
+ url(ur'^Юникод/(\w+)/$', views.client, name=u"метка_оператора"),
)
Please sign in to comment.
Something went wrong with that request. Please try again.