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

Exception when decoding path parameters containing brackets #691

Open
jowerner opened this issue Jan 26, 2021 · 0 comments
Open

Exception when decoding path parameters containing brackets #691

jowerner opened this issue Jan 26, 2021 · 0 comments

Comments

@jowerner
Copy link

Decoding successfully extracted path parameters sometimes fails with an IllegalArgumentException / URISyntaxException. This happens for path segments containing special characters, brackets in my case.

java.lang.IllegalArgumentException: Illegal character in path at index 7: foo/bar[1].png
    at java.base/java.net.URI.create(URI.java:883)
    at ninja.utils.AbstractContext.getPathParameter(AbstractContext.java:195)
    at ninja.params.ArgumentExtractors$PathParamExtractor.extract(ArgumentExtractors.java:133)
    at ninja.params.ArgumentExtractors$PathParamExtractor.extract(ArgumentExtractors.java:124)
    at ninja.params.ControllerMethodInvoker.invoke(ControllerMethodInvoker.java:70)
    ...
Caused by: java.net.URISyntaxException: Illegal character in path at index 7: foo/bar[1].png
    at java.base/java.net.URI$Parser.fail(URI.java:2913)
    at java.base/java.net.URI$Parser.checkChars(URI.java:3084)
    at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3166)
    at java.base/java.net.URI$Parser.parse(URI.java:3125)
    at java.base/java.net.URI.<init>(URI.java:600)
    at java.base/java.net.URI.create(URI.java:881)
    ... 50 more

To decode a path parameter, Ninja uses the URI class. This class does not accept literal brackets, hence the exception. Browsers, however, don't convert brackets in the path, while other special characters are sent encoded. Seems there is a discrepancy what characters are allowed in a URL.

What do you think about using a path parameter decoder that is less strict and accepts all special characters that are sent literally by browsers? Thanks!

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