Skip to content

Commit 0ad84e3

Browse files
authored
Update REGEX for file extensions (#62)
1 parent a464fe5 commit 0ad84e3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sanic_routing/patterns.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def process(
7979
class ExtParamInfo(ParamInfo):
8080
def __init__(self, **kwargs):
8181
super().__init__(**kwargs)
82-
match = REGEX_PARAM_NAME_EXT.match(self.raw_path)
82+
match = REGEX_PARAM_EXT_PATH.search(self.raw_path)
8383
if not match:
8484
raise InvalidUsage(
8585
f"Invalid extension parameter definition: {self.raw_path}"
@@ -133,10 +133,12 @@ def process(self, params, value):
133133

134134

135135
EXTENSION = r"[a-z0-9](?:[a-z0-9\.]*[a-z0-9])?"
136-
REGEX_PARAM_NAME = re.compile(r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?::(.*))?>$")
137-
REGEX_PARAM_NAME_EXT = re.compile(
138-
r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?:=([a-z]+))?(?::ext(?:=([a-z0-9|\.]+))?)>$"
136+
PARAM_EXT = (
137+
r"<([a-zA-Z_][a-zA-Z0-9_]*)(?:=([a-z]+))?(?::ext(?:=([a-z0-9|\.]+))?)>"
139138
)
139+
REGEX_PARAM_NAME = re.compile(r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?::(.*))?>$")
140+
REGEX_PARAM_EXT_PATH = re.compile(PARAM_EXT)
141+
REGEX_PARAM_NAME_EXT = re.compile(r"^" + PARAM_EXT + r"$")
140142
REGEX_ALLOWED_EXTENSION = re.compile(r"^" + EXTENSION + r"$")
141143

142144
# Predefined path parameter types. The value is a tuple consisteing of a

0 commit comments

Comments
 (0)