From af467100175aec451ecfc03f21027d9f013c02c1 Mon Sep 17 00:00:00 2001 From: nikto_b Date: Sat, 19 Jul 2025 04:12:46 +0300 Subject: [PATCH] Make router matcher lazy --- src/turbosloth/router.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/turbosloth/router.py b/src/turbosloth/router.py index e9817a1..c125180 100644 --- a/src/turbosloth/router.py +++ b/src/turbosloth/router.py @@ -42,8 +42,8 @@ class Route: if '}' not in part: raise ValueError(f'Invalid subpath substitute placeholder: {part}') re_part = part.replace('(', '\\(').replace(')', '\\)') - names = re.findall(r'\{(.*)}', part) - re_part = re.sub(r'\{.*}', r'(.*)', re_part) + names = re.findall(r'\{(.*?)}', part) + re_part = re.sub(r'\{.*?}', r'(.*?)', re_part) re_part = re.compile('^' + re_part + '$') d = self._find_regexp_subroute(re_part) @@ -100,10 +100,12 @@ class Router: def add(self, method: MethodType, path_pattern: str, handler: InternalHandlerType) -> None: method = typing.cast(MethodType, method.upper()) - substitutes = re.findall(r'\{(.*)}', path_pattern) + substitutes = re.findall(r'\{(.*?)}', path_pattern) if len(substitutes) > 0: subst = [] for s in substitutes: + if isinstance(s, str): + s = [s] subst += list(s) if len(subst) != len(set(subst)): raise ValueError('Duplicate path substitute names are prohibited')