'Exception is thrown when input with % is send to the back end - Thymeleaf
I have some html text inputs which send data to a back-end spring system. When I put just a (%) as a character I am getting the following Exception:
java.lang.IllegalArgumentException: Incomplete escaping sequence in input
14:17:34,269 INFO [stdout] (default task-4) at org.unbescape.uri.UriEscapeUtil.unescape(UriEscapeUtil.java:617)
14:17:34,269 INFO [stdout] (default task-4) at org.unbescape.uri.UriEscape.unescapeUriQueryParam(UriEscape.java:1702)
14:17:34,269 INFO [stdout] (default task-4) at org.unbescape.uri.UriEscape.unescapeUriQueryParam(UriEscape.java:1668)
14:17:34,269 INFO [stdout] (default task-4) at org.thymeleaf.spring5.util.SpringRequestUtils.checkViewNameNotInRequest(SpringRequestUtils.java:55)
14:17:34,269 INFO [stdout] (default task-4) at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:275)
14:17:34,269 INFO [stdout] (default task-4) at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190)
I am encoding the data before is sent to the back-end using JS's encodeURIComponent method and in the link the % becomes %25 which is the correct encoded value but why does it throw an exception and what is the possible solution to this I am out of ideas tbh.
Thank you in advance for your responses :)
Solution 1:[1]
You did not disclose more information other than "When I put just a (%) as a character" and "I am encoding the data".
My crystal bulb is telling me there is some http(s) request and one of the request parameters contains an encoded percentage sign only. When this request is parsed by the server the %25 is decoded back into %. So far no problem.
But is it possible that the application now tries to decode the data itself and just sees the % sign? Then it would come back with exactly the error that you see.
In that case you might want to double encode: % -> %25 -> %2525
Solution 2:[2]
change your thymeleaf version.
<properties>
<thymeleaf.version>3.0.13.RELEASE</thymeleaf.version>
</properties>
for more information about this bug, you can read about it. hope it will resolve your issue.[Thymeleaf Issue#255] [1]: https://github.com/thymeleaf/thymeleaf-spring/issues/255
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hiran Chaudhuri |
| Solution 2 | Faisal Shahzad |
