#20022 closed Bug (fixed)
reverse() breaks on URLs which include a ~ character
Reported by: | Owned by: | Baptiste Mispelon | |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | bmispelon@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Testing on my local machine through Apache, so the root URL is at:
Calling reverse on one of my views inside views.py, e.g.:
s = reverse(locate_task_enter, args=(task_id,))
Breaks with the cryptic message:
"a float is required"
A little examination reveals what's going on. Break is at line 391 of urlresolvers.py.
candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
prefix_norm is:
u'/%7Emxheyeck/sicariid/'
So line 391 is equivalent to:
u'/%7Emxheyeck/sicariid/locate_task_enter/%(task_id)s/' % {u'task_id': u'419'}
Where '%7E' is both a urlencoded tilde and, unfortunately, an upper-case floating-point exponential. So, boom.
I attach the local vars from the break at 391.
val 419L pattern 'locate_task_enter/(?P<task_id>\\d+)/$' self <RegexURLResolver 'sitespecific.urls' (None:None) ^/> args (419L,) _prefix u'/~mxheyeck/sicariid/' possibility [(u'locate_task_enter/%(task_id)s/', [u'task_id'])] unicode_args [u'419'] possibilities [([(u'locate_task_enter/%(task_id)s/', [u'task_id'])], 'locate_task_enter/(?P<task_id>\\d+)/$', {})] lookup_view <function locate_task_enter at 0x1065f8668> prefix_norm u'/%7Emxheyeck/sicariid/' prefix_args [] params [u'task_id'] result u'locate_task_enter/%(task_id)s/' defaults {} kwargs {}
Change History (5)
comment:1 by , 12 years ago
Component: | Uncategorized → Core (URLs) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 12 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
This seems to have been overlooked when fixing #18210.
The fix should be similar: escape any
%
present in the prefix.Note that a temporary workaround is to used named arguments (
kwargs
) for reverse.