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

route_param regex is broken by R::Routes::Endpoint::_build_regex if contains quantifiers... #119

Open
lmasarati opened this issue Jul 1, 2022 · 0 comments

Comments

@lmasarati
Copy link

lmasarati commented Jul 1, 2022

Hello,
I think there could be a problem with the line

$regex =~ s/[{}]//g;

in Raisin::Routes::Endpoint

sub _build_regex {
    my $self = shift;
    return $self->path if ref($self->path) eq 'Regexp';
 
    my $regex = $self->path;
 
    $regex =~ s/(.?)([:*?])(\w+)/$self->_rep_regex($1, $2, $3)/eg;
    $regex =~ s/[{}]//g;
 
    # Allows any extensions
    $regex .= "(?:\\\.[^.]+?)?";
 
    qr/^$regex$/;
}

If I define a route_param as

resource 'backup' => sub {
	params (
		requires('sessionId',
			type => Str,
			regex => qr/^[a-f0-9]{32}$/
		)
	);
	route_param 'sessionId' => sub {
...

then the aforementioned line translates the regex to

'regex' => qr/^\/backup\/(?<sessionId>(?i:[a-f0-9]32))(?:\.[^.]+?)?$/,

The workaround is to remove the regex from params definition, leaving as generic Str and check it later during the execution of sub...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant