0

Text staring with % is not decoded in java UTF8. But if % is entered following characters UTF8 decodes it correctly. I entered "%kj" in the form field

param.message=encodeURIComponent(message);
String message = URLDecoder.decode(request.getParameter("message"), "UTF-8");

Getting this error:

java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "kj"

Ivam
  • 379
  • 3
  • 12
Abhi
  • 41
  • 2
  • 9
  • according to the [docs](https://docs.oracle.com/javase/7/docs/api/java/net/URLDecoder.html), `The character "%" is allowed but is interpreted as the start of a special escaped sequence.` "%kj" is not a valid escaped sequence. – Dan O Jul 13 '18 at 14:42
  • Possible duplicate [https://stackoverflow.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string](https://stackoverflow.com/questions/6067673/urldecoder-illegal-hex-characters-in-escape-pattern-for-input-string) – pbachman Jul 13 '18 at 14:43
  • 2
    Java should be getting `%25kj` rather than `%kj` though, where `%25` is the URL encoding for the `%` character. It's possible that you are trying to URLDecode a message that's already been decoded. – Aaron Jul 13 '18 at 14:44
  • "Java" probably is getting it. but it's impossible to tell without more code if the string has already been decoded somewhere else. (oops! just saw your edit update. I agree) – Dan O Jul 13 '18 at 14:47
  • String is not decoded yet. We are trying to decode it by getting that parameter through request. We tried using MimeUtility.encodeText(body,"UTF-8","BASE64") and it worked but dont know whether using this is correct or not. – Abhi Jul 13 '18 at 14:52

0 Answers0