Opened 7 years ago

Closed 7 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: master
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: UI/UX:

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 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to anonymous
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 7 years ago by anonymous

  • Status changed from assigned to new

comment:3 Changed 7 years ago by anonymous

  • Owner changed from anonymous to nobody

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from new to closed

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

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