Skip to content

Commit

Permalink
Update REGEX for file extensions (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins authored Mar 31, 2022
1 parent a464fe5 commit 0ad84e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sanic_routing/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0ad84e3

Please sign in to comment.