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

UriTemplate regex operates on unnormalized URIs #603

Open
vojtechtoman opened this issue Mar 25, 2021 · 1 comment
Open

UriTemplate regex operates on unnormalized URIs #603

vojtechtoman opened this issue Mar 25, 2021 · 1 comment

Comments

@vojtechtoman
Copy link

Path variables in a URI template can specify a regex to limit the matches. However, since http4k applies the regex to the raw, "unnormalized" URI, the regex needs to deal with all possible identical URIs encodings: /test/abc, /test/%61bc, etc., which is unrealistic. I think http4k should normalize the URI first before passing it to the UriTemplate.

Reproducer:

val routes = routes(
    "/test/{param:[a-zA-Z0-9]+}" bind GET to {
        Response(Status.OK)
    }
)
routes(Request(GET, "/test/abc")).status // 200 OK
routes(Request(GET, "/test/%61bc")).status // 404 Route not found
@time4tea
Copy link
Contributor

time4tea commented Apr 8, 2021

It is a bit complicated. You cannot treat the URI path as a single element and normalize it. You have consider each path part independently. For example: /article/doi/10.1002%2F0470841559.ch1 - is not the same as /article/doi/10.1002/0470841559.ch1

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

2 participants