Opened 17 years ago
Closed 17 years ago
#6333 closed (wontfix)
urlresolvers.resolve barfs on regexps with a flag group
Reported by: | 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)
Change History (5)
by , 17 years ago
Attachment: | django-regexp-flags.diff added |
---|
comment:1 by , 17 years ago
by , 17 years ago
Attachment: | django-regexp-flags.2.diff added |
---|
comment:2 by , 17 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:3 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
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.