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 and dot in parameter #14

Open
vlet opened this issue May 19, 2015 · 8 comments · May be fixed by #112
Open

route_param and dot in parameter #14

vlet opened this issue May 19, 2015 · 8 comments · May be fixed by #112
Assignees

Comments

@vlet
Copy link
Contributor

vlet commented May 19, 2015

Parameters captured by route_param can't contain dots.

For example, route '/:name'

params requires => { name => "name", type => Str };
route_param 'name' => sub {
    get sub {
        [ "hello" => shift->{name} ]
    }
}

This is ok

$ curl 'http://0:5000/username'
["hello" : "username"]

but this isn't

$ curl 'http://0:5000/user.name'
Nothing found
@khrt khrt self-assigned this May 20, 2015
khrt pushed a commit that referenced this issue May 31, 2015
@khrt
Copy link
Owner

khrt commented May 31, 2015

please confirm you do not have such an error with latest Raisin from master branch. thanks

@vlet
Copy link
Contributor Author

vlet commented Jun 2, 2015

problem persists.

This is due to _rep_regex() expects that path do not contains dots and slashes '[^/.]+' at https://github.com/khrt/Raisin/blob/master/lib/Raisin/Routes/Endpoint.pm#L68

@khrt
Copy link
Owner

khrt commented Jun 2, 2015

ok, I understood, I had thought the problem was in a not found error. Thanks, will fix in a couple of days.

@khrt
Copy link
Owner

khrt commented Jun 10, 2015

i fixed it but it looks like a temporary solution.

thanks a lot for the report.

@khrt khrt closed this as completed Jun 10, 2015
@khrt khrt assigned khrt and unassigned khrt Oct 7, 2016
@khrt khrt added the bug label Dec 30, 2016
@vlet
Copy link
Contributor Author

vlet commented Jan 11, 2017

Bug was reintroduced. Now it returns 406 error for parameters with dots.

@khrt khrt reopened this Jan 11, 2017
@khrt
Copy link
Owner

khrt commented Jan 11, 2017

@vlet, unfortunately I don't know how to fix it right now.

After introducing a Formatter middleware the logic has been changed a bit.

Previously the cause of the issue was in Router, it hadn't been finding the endpoint because the part of the URI after the full stop wasn't involved in the matching.

Now Router finds any routes, but Formatter splits the URI by fullstops and considers the last part as a format; it throws an 406 error in case encoder is not found, which is happening in your case.

You can try to avoid this behaviour specifying the proper extension with the latest master branch, like

$ curl 'http://0:5000/user.name.json'
["hello","user.name"]

It's a workaround until I can come with a better solution.

@vlet
Copy link
Contributor Author

vlet commented Jan 11, 2017

Ok, thanks

@hidden-primary-net
Copy link
Contributor

Hi,

we also stumbled upon this issue. I was able to follow it down to lib/Raisin/Middleware/Formatter.pm.

If there is a dot "." anywhere in the entire path the remainder of the path is considered an "extension", even if there are slashes following the dot, e.g.:

$ curl --noproxy \* -i http://localhost:5000/check/D.a/all
HTTP/1.0 406 Not Acceptable
Date: Tue, 27 Apr 2021 17:24:21 GMT
Server: HTTP::Server::PSGI
Content-Length: 0

The unfortunate magic happens in Raisin::Middleware::Formatter->_path_has_extension. I'm not quite sure how to fix it. My first attempt was to examine only the "file" part:

@@ -71,6 +73,8 @@ sub call {
 sub _accept_header_set { length(shift || '') }
 sub _path_has_extension {
     my $path = shift;
+    my $idx_last_slash = rindex $path, '/';
+    $path = $idx_last_slash >= 0 ? substr $path, $idx_last_slash : $path;
     my @chunks = split /\./, $path;
     scalar(@chunks) > 1;
 }

This would solve my current problem.

But it should (somehow) be checked if this "extension" can be handled properly?

hidden-primary-net added a commit to hidden-primary-net/Raisin that referenced this issue Apr 28, 2021
Do not interpret "." in path names as a file extension.
hidden-primary-net added a commit to hidden-primary-net/Raisin that referenced this issue Apr 28, 2021
Do not interpret "." in path names as a file extension.
khrt pushed a commit that referenced this issue May 6, 2021
khrt pushed a commit that referenced this issue May 6, 2021
khrt pushed a commit that referenced this issue May 6, 2021
@khrt khrt linked a pull request May 6, 2021 that will close this issue
khrt pushed a commit that referenced this issue May 10, 2021
khrt pushed a commit that referenced this issue May 10, 2021
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

Successfully merging a pull request may close this issue.

3 participants