Skip to content

Commit f46d9d1

Browse files
committed
allow customizable match_any_identifier
1 parent e92842f commit f46d9d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/reactpy_router/resolvers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88

99

1010
class Resolver:
11-
"""A simple route resolver that uses regex to match paths"""
11+
"""A simple route resolver that uses regex to match paths."""
1212

1313
def __init__(
1414
self,
1515
route: Route,
1616
param_pattern=r"{(?P<name>\w+)(?P<type>:\w+)?}",
17+
match_any_identifier=r"\*$",
1718
converters: dict[str, ConversionInfo] | None = None,
1819
) -> None:
1920
self.element = route.element
2021
self.pattern, self.converter_mapping = self.parse_path(route.path)
2122
self.converters = converters or CONVERTERS
2223
self.key = self.pattern.pattern
2324
self.param_regex = re.compile(param_pattern)
25+
self.match_any = match_any_identifier
2426

2527
def parse_path(self, path: str) -> tuple[re.Pattern[str], ConverterMapping]:
2628
pattern = "^"
@@ -39,8 +41,8 @@ def parse_path(self, path: str) -> tuple[re.Pattern[str], ConverterMapping]:
3941
last_match_end = match.end()
4042
pattern += f"{re.escape(path[last_match_end:])}$"
4143

42-
# Replace literal `*` with "match anything" regex pattern, if it's at the end of the path
43-
if pattern.endswith(r"\*$"):
44+
# Replace "match anything" pattern with regex, if it's at the end of the path
45+
if pattern.endswith(self.match_any):
4446
pattern = f"{pattern[:-3]}.*$"
4547

4648
return re.compile(pattern), converter_mapping

0 commit comments

Comments
 (0)