The following 2 lines:
|
rule = re.sub("/{2,}?", "/", self.rule) |
|
path = re.sub("/{2,}?", "/", path) |
Uses a non-greedy quantifier. But {2,} suggests it wants to recognize 2 or more repetitions, but {2,}? will only match 2 repetitions.
A small test script:
import re
def _merge_slashes(url:str, re_str:str):
print(f' using {repr(re_str)}:', re.sub(re_str, "/", url))
def merge_slashes(url:str):
print(f'Merge: {url}')
_merge_slashes(url, "/{2,}?")
_merge_slashes(url, "/{2,}")
merge_slashes('/path/to/foo')
merge_slashes('//path//to//foo')
merge_slashes('///path///to///foo')
merge_slashes('////path////to////foo')
with output:
Merge: /path/to/foo
using '/{2,}?': /path/to/foo
using '/{2,}': /path/to/foo
Merge: //path//to//foo
using '/{2,}?': /path/to/foo
using '/{2,}': /path/to/foo
Merge: ///path///to///foo
using '/{2,}?': //path//to//foo
using '/{2,}': /path/to/foo
Merge: ////path////to////foo
using '/{2,}?': //path//to//foo
using '/{2,}': /path/to/foo
The following 2 lines:
werkzeug/src/werkzeug/routing/rules.py
Line 725 in 64b09e7
werkzeug/src/werkzeug/routing/matcher.py
Line 181 in 64b09e7
Uses a non-greedy quantifier. But
{2,}suggests it wants to recognize 2 or more repetitions, but{2,}?will only match 2 repetitions.A small test script:
with output: