@@ -98,7 +98,7 @@ def _validate_multi_segment_value(val: str) -> bool:
9898 bool: True if the value is valid and does not violate traversal boundaries,
9999 False otherwise.
100100 """
101- if val in ('' , '.' , '..' ):
101+ if val in ("" , "." , ".." ):
102102 return False
103103
104104 segments = val .split ("/" )
@@ -138,34 +138,32 @@ def _build_capture_pattern(template_str: str) -> tuple[re.Pattern, tuple[str, ..
138138 - A list of wildcard type strings ('*' or '**') in matching order.
139139 """
140140 wildcard_types = []
141+ parts = []
142+ last_idx = 0
143+ for match in _VARIABLE_RE .finditer (template_str ):
144+ literal = template_str [last_idx : match .start ()]
145+ parts .append (re .escape (literal ))
141146
142- def replacer (match ):
143147 positional = match .group ("positional" )
144148 template = match .group ("template" )
145149
146150 if positional == "*" :
147151 wildcard_types .append ("*" )
148- return _SINGLE_SEGMENT_PATTERN
152+ replaced = _SINGLE_SEGMENT_PATTERN
149153 elif positional == "**" :
150154 wildcard_types .append ("**" )
151- return _MULTI_SEGMENT_PATTERN
155+ replaced = _MULTI_SEGMENT_PATTERN
152156 elif not template or template == "*" :
153157 wildcard_types .append ("*" )
154- return _SINGLE_SEGMENT_PATTERN
158+ replaced = _SINGLE_SEGMENT_PATTERN
155159 elif template == "**" :
156160 wildcard_types .append ("**" )
157- return _MULTI_SEGMENT_PATTERN
161+ replaced = _MULTI_SEGMENT_PATTERN
158162 else :
159163 sub_pattern , sub_types = _build_capture_pattern (template )
160164 wildcard_types .extend (sub_types )
161- return sub_pattern .pattern
165+ replaced = sub_pattern .pattern
162166
163- parts = []
164- last_idx = 0
165- for match in _VARIABLE_RE .finditer (template_str ):
166- literal = template_str [last_idx : match .start ()]
167- parts .append (re .escape (literal ))
168- replaced = replacer (match )
169167 parts .append (replaced )
170168 last_idx = match .end ()
171169 literal = template_str [last_idx :]
0 commit comments