Rendering bulgarian texts ends up as UTF-16 escaped
See original GitHub issueHello,
I’m using thymeleaf 3.0.9.RELEASE and I’m rendering the following Bulgarian text: “Безплатна доставка на следващия ден” and it ends up rendered as \u0411\u0435\u0437\u043F\u043B\u0430\u0442\u043D\u0430 \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0430 \u043D\u0430 \u0441\u043B\u0435\u0434\u0432\u0430\u0449\u0438\u044F \u0434\u0435\u043D
Here’s my method:
@Override
public String parseContent(@Nonnull final String content, final Map<String, Object> params) {
Assert.notNull(content, "Parameter content must be non-null");
return templateEngine.process("<span th:inline=\"javascript\">" + content + "</span>", createSpringWebContext(params));
}
Where content is
“Купете стоки на стойност повече от [[${currencyFormatter.print(promotion.activeSubtotalThreshold, locale)}]] за да получите [[${promotion.quantity}]] of [[${promotion.product.getName(locale)}]] БЕЗПЛАТНО!”
and promotion is a variable in the context with name in Bulgarian locale being “Безплатна доставка на следващия ден”.
I found out the problem is because when you are creating your JacksonStandardJavaScriptSerializer
you are specifying this:
this.mapper.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
making it like this:
this.mapper.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
works perfectly fine. I will submit a PR.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hi @danielfernandez
thank you for the response - it works perfectly fine with no javascript inlining. I guess I was confused because this used to work with thymeleaf 2.x
Once again, thank you for your fast response.
OK, but what I mean is that apparently you are rendering that text inside an HTML element (
<span>
), but you are usingth:inline="javascript"
, which considers what is processed inside as JavaScript code and therefore applies Jackson and, in your case, JavaScript-escaping. Thus the unicode escapes, which are perfectly valid JavaScript escaped text.So I’m confused about your use of
th:inline="javascript"
in a<span>
element. If you are doing that only because you want your[[${...}]]
expressions resolved, and seeing you are using Thymeleaf 3.0, you don’t really have to use inlining at all.Assuming you are using the
StringTemplateResolver
, this:or even simply this:
…should work for you. There will be escaping anyway for your Bulgarian characters, but it will be HTML escaping and not JavaScript, which I presume is what you are looking for.