Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use ()? in regex path definition #24

Open
vincentsarago opened this issue Oct 2, 2019 · 0 comments
Open

Can't use ()? in regex path definition #24

vincentsarago opened this issue Oct 2, 2019 · 0 comments
Assignees
Labels

Comments

@vincentsarago
Copy link
Owner

@app.route( 
    r"/test/<regex(user(\d+)?):user>/<sport>" ) 
def test(user, sport): 
    return ("OK", "text/plain", "YO")

this will fail here

def _get_matching_args(self, route: RouteEntry, url: str) -> Dict:
route_expr = re.compile(route.route_regex)
route_args = [i.group() for i in params_expr.finditer(route.path)]
url_args = route_expr.match(url).groups()
names = [param_pattern.match(arg).groupdict()["name"] for arg in route_args]
args = [
_converters(u, route_args[id])
for id, u in enumerate(url_args)
if u != route_args[id]
]

because url_args = route_expr.match(url).groups() will return ('user1234', '1234', 'rugby')

fix

Use patterns ?

@vincentsarago vincentsarago self-assigned this Oct 2, 2019
vincentsarago added a commit that referenced this issue Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant