Opened 17 years ago

Last modified 13 years ago

#4772 closed

urlresolver fails to resolve urls with unicode — at Version 1

Reported by: alexthreed@… Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: Keywords: unicode
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

Traceback (most recent call last):
File "C:\python24\Lib\site-packages\django\template\__init__.py" in render_node
  754. result = node.render(context)
File "C:\python24\Lib\site-packages\django\template\defaulttags.py" in render
  134. nodelist.append(node.render(context))
File "C:\python24\Lib\site-packages\django\template\__init__.py" in render
  790. return self.filter_expression.resolve(context)
File "C:\python24\Lib\site-packages\django\template\__init__.py" in resolve
  582. obj = resolve_variable(self.var, context)
File "C:\python24\Lib\site-packages\django\template\__init__.py" in resolve_variable
  680. current = current()
File "C:\python24\Lib\site-packages\django\utils\functional.py" in _curried
  3. return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "C:\python24\Lib\site-packages\django\db\models\base.py" in get_absolute_url
  457. return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.module_name), func)(self)
File "C:\python24\Lib\site-packages\django\db\models\__init__.py" in inner
  27. return reverse(bits[0], None, *bits[1:3])
File "C:\python24\lib\site-packages\django\core\urlresolvers.py" in reverse
  289. return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
File "C:\python24\lib\site-packages\django\core\urlresolvers.py" in reverse
  275. return u''.join([reverse_helper(part.regex, *args, **kwargs) for part in self.reverse_dict[lookup_view]])
File "C:\python24\lib\site-packages\django\core\urlresolvers.py" in reverse_helper
  90. result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern)
File "C:\python24\lib\sre.py" in sub
  142. return _compile(pattern, 0).sub(repl, string, count)
File "C:\python24\lib\site-packages\django\core\urlresolvers.py" in __call__
  130. if not re.match(test_regex + '$', str(value)): # TODO: Unicode?

  UnicodeEncodeError at /
  'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)

Change History (2)

by alexthreed@…, 17 years ago

Attachment: urlresolvers_unicode.patch added

comment:1 by Malcolm Tredinnick, 17 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

(Fixed description formatting.)

This might be trickier to fix than this patch. The problem is the way reverse matching is used: we need to think about whether reverse should return a valid URL (in which case it must be converted from an IRI to a URI) or whether that is the responsibility of the caller.

Can you provide an example of how this problem is triggered please, so that we can write a test case.

Note: See TracTickets for help on using tickets.
Back to Top