Opened 17 years ago

Closed 17 years ago

#6333 closed (wontfix)

urlresolvers.resolve barfs on regexps with a flag group

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

Description

I think I've just run across a small bug with the reverse() method in urlresolvers.py 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@… 17 years ago.
django-regexp-flags.2.diff (1.3 KB ) - added by leif@… 17 years ago.

Download all attachments as: .zip

Change History (5)

by leif@…, 17 years ago

Attachment: django-regexp-flags.diff added

comment:1 by leif@…, 17 years ago

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.

by leif@…, 17 years ago

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

comment:2 by Simon Greenhill <dev@…>, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Malcolm Tredinnick, 17 years ago

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