From 0ad84e3d61382bb38685844b15f3b5eb4ea38fd9 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Thu, 31 Mar 2022 11:34:51 +0300 Subject: [PATCH] Update REGEX for file extensions (#62) --- sanic_routing/patterns.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sanic_routing/patterns.py b/sanic_routing/patterns.py index 9dd816b..8bb777f 100644 --- a/sanic_routing/patterns.py +++ b/sanic_routing/patterns.py @@ -79,7 +79,7 @@ def process( class ExtParamInfo(ParamInfo): def __init__(self, **kwargs): super().__init__(**kwargs) - match = REGEX_PARAM_NAME_EXT.match(self.raw_path) + match = REGEX_PARAM_EXT_PATH.search(self.raw_path) if not match: raise InvalidUsage( f"Invalid extension parameter definition: {self.raw_path}" @@ -133,10 +133,12 @@ def process(self, params, value): EXTENSION = r"[a-z0-9](?:[a-z0-9\.]*[a-z0-9])?" -REGEX_PARAM_NAME = re.compile(r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?::(.*))?>$") -REGEX_PARAM_NAME_EXT = re.compile( - r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?:=([a-z]+))?(?::ext(?:=([a-z0-9|\.]+))?)>$" +PARAM_EXT = ( + r"<([a-zA-Z_][a-zA-Z0-9_]*)(?:=([a-z]+))?(?::ext(?:=([a-z0-9|\.]+))?)>" ) +REGEX_PARAM_NAME = re.compile(r"^<([a-zA-Z_][a-zA-Z0-9_]*)(?::(.*))?>$") +REGEX_PARAM_EXT_PATH = re.compile(PARAM_EXT) +REGEX_PARAM_NAME_EXT = re.compile(r"^" + PARAM_EXT + r"$") REGEX_ALLOWED_EXTENSION = re.compile(r"^" + EXTENSION + r"$") # Predefined path parameter types. The value is a tuple consisteing of a