Opened 10 years ago

Closed 10 years ago

#6333 closed (wontfix)

urlresolvers.resolve barfs on regexps with a flag group

Reported by: leif@… Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I think I've just run across a small bug with the reverse() method in for URLs that contain a flag group (like (?u)). To replicate, construct a urlconf containing a regexp with a flag group, e.g.

  url(r'(?u)^foo/(?P<id>\d+)/$', name='foo-url')

and then use django.core.urlresolvers.reverse to construct a url with parameters:

  reverse('foo-url', kwargs=dict(id=12))

I get a NoMatchError here (not enough positional arguments), but I don't if I remove the flag group at the beginning of the url regexp.

I've attached a small patch for this issue ; the Python re docs state that a flag group should be the first non-whitespace content in the regexp, so I only cover that case.

Attachments (2)

django-regexp-flags.diff (1.2 KB) - added by leif@… 10 years ago.
django-regexp-flags.2.diff (1.3 KB) - added by leif@… 10 years ago.

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by leif@…

Attachment: django-regexp-flags.diff added

comment:1 Changed 10 years ago by leif@…

Sorry, I just re-read the Python re docs and I realized only the x flag has to be at the beginning of the regexp. I've updated the patch to ignore all flag groups in the url regexp.

Changed 10 years ago by leif@…

Attachment: django-regexp-flags.2.diff added

comment:2 Changed 10 years ago by Simon Greenhill <dev@…>

Triage Stage: UnreviewedReady for checkin

comment:3 Changed 10 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

Not worth fixing quite like this. Firstly, in this particular case, you don't need the "u" flag, since all of those matches are done with re.UNICODE being used. Secondly, a rewrite of that portion of the code is in progress that fixes things a bit more holistically.

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