Better handling of regular expressions for reverse urlresolver
|Reported by:||SmileyChris||Owned by:||mtredinnick|
|Cc:||albertpeschar+djangotrac@…, mattimustang@…, dcwatson@…, alexander.solovyov@…, daybreaker12@…, wbyoung@…, django@…, eric@…, beau@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I spent a bit of time looking over the urlresolvers.py today. I put together a patch fixing some problems with it.
Firstly, regular expressions should be set up outside the function so they only have to be compiled once (fix 1).
A TODO: was to make the resolver handle recursive parenthesis. After a bit of thinking (and actually making it work like that) I realised that is actually not what you'd need to do. Recursion is not necessary because the outermost matched parenthesis will be replaced with the given argument anyway.
What was needed was a rethink of choosing between named/unnamed groups. It should be named groups only (if any exist) for each whole regular expression (fix 2).
It does need to handle non-grouping parenthesis recursively though (fix 3).
Other expression extension notations (apart from named groups, of course) should be ignored (fix 4).
Probably rarely needed, but it now also handles pipes in regular expressions (fix 5).
Change History (36)
comment:7 Changed 7 years ago by SmileyChris
- Triage Stage changed from Unreviewed to Design decision needed
comment:17 Changed 7 years ago by mtredinnick
- Owner changed from adrian to mtredinnick
- Summary changed from [patch] Better handling of regular expressions for reverse urlresolver to Better handling of regular expressions for reverse urlresolver
- Triage Stage changed from Design decision needed to Accepted
comment:18 Changed 7 years ago by Alexander Solovyov <alexander.solovyov@…>
- Cc alexander.solovyov@… added
comment:22 Changed 7 years ago by Matthew Flanagan <mattimustang@…>
- Cc mattimustang@… added
- Patch needs improvement set
Changed 6 years ago by andresj
comment:29 Changed 6 years ago by mtredinnick
- Resolution set to fixed
- Status changed from new to closed