In our web service we set a cookie through JavaScript wich we read again in Java (Servlet)
However we need to escape the value of the cookie because it may contain i
Common lang's StringEscapeUtils didn't work for me.
You can simply use javascript nashorn engine to unescape a escaped javascript string.
private String decodeJavascriptString(final String encodedString) {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
Invocable invocable = (Invocable) engine;
String decodedString = encodedString;
try {
decodedString = (String) invocable.invokeFunction("unescape", encodedString);
} catch (ScriptException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return decodedString;
}