Home > other >  Exception is thrown when input with % is send to the back end - Thymeleaf
Exception is thrown when input with % is send to the back end - Thymeleaf

Time:11-12

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 % 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 :)

CodePudding user response:

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 % 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

  • Related