Opened 16 years ago

Closed 16 years ago

#6729 closed (duplicate)

reverse() and {% url %} don't work with slightly-more-advanced regexes

Reported by: albertpeschar@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: url dispatcher reverse regex
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This works fine:

# urls.py
urlpatterns = patters('ads.admanager.view',
    (r'^ad/(?P<id>\d+).html$', 'ad'),
)

# somewhere else (e.g. python manage.py shell)
from django.core.urlresolvers import reverse
url = reverse('ads.admanager.views.ad', kwargs={'id': 123}) # ad/123.html

Note that the regex used also matches e.g. ad/123xhtml , or any other character because of the "." that is not escaped.


This doesn't work:

# urls.py
urlpatterns = patters('ads.admanager.view',
    (r'^ad/(?P<id>\d+)\.html$', 'ad'), # <-- see the escape ( \. )
)

# somewhere else (e.g. python manage.py shell)
from django.core.urlresolvers import reverse
url = reverse('ads.admanager.views.ad', kwargs={'id': 123}) # ad/123\.html or ad/123%5C.html

Expected: ad/123.html
Got: ad/123\.html

And, yes, I used the SVN version ;-)

Change History (4)

comment:1 by anonymous, 16 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:2 by anonymous, 16 years ago

Status: assignednew

comment:3 by anonymous, 16 years ago

Owner: changed from anonymous to nobody

comment:4 by Malcolm Tredinnick, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #2977, which I'm slowly working on fixing.

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