I have a string like http://google.com/search/q=<%= name %>
.
A third party js library that I have no control over is escaping this to "http://google.com/search/q=%3C%=%20name%20%%3E"
which Javascript can successfully unescape to the original string with
unescape("http://google.com/search/q=%3C%=%20name%20%%3E")
But Java's URLDecode.decode("http://google.com/search/q=%3C%=%20name%20%%3E")
throws an IllegalArgumentException
because of the unescaped literal %
character in the string which is of course correct and according to spec, but this makes server-side processing complicated.
Before I try to fix the bad JS escape on the server-side with regular expressions (because, as mentioned, I cannot modify the JS side), I would like to know if there is a more permissive Java URL/URI decoding API which would work in the same way as Javascript's unescape
, i.e. which would ignore standalone '%' characters and only decode whatever is decodable.