Better handling of regular expressions for reverse urlresolver
|Reported by:||Chris Beaven||Owned by:||Malcolm Tredinnick|
|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).
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:17 Changed 9 years ago by
|Owner:||changed from Adrian Holovaty to Malcolm Tredinnick|
|Summary:||[patch] Better handling of regular expressions for reverse urlresolver → Better handling of regular expressions for reverse urlresolver|
|Triage Stage:||Design decision needed → Accepted|