using javascript inline expression in a Chinese character set
See original GitHub issueI have a problem when using javascript inline expression in GBK ( a Chinese character set)encoding environment. thymeleaf version is 3.0.7,jackson verson is 2.5.0
<script th:inline="javascript">
var user = [[${sessCtx.username}]];
</script>
sessCtx.username contain some chinese characters . like “张三”. but what I got is :
var user = "\u82CF\u5DDE";
I can transform in front end, but this is not a normal way. What can I do to get a right string in back end.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
how to inject chinese characters using javascript?
If the script is inline (in the HTML file), then it's using the encoding of the HTML file and you won't have an...
Read more >Use Javascript to replace Chinese characters/match Chinese ...
Today, I asked a question about the regular expression of js Chinese characters, so let's record it. Use Javascript to replace Chinese.
Read more >JS Character Encodings - InfoQ
This is one example of a character encoding that was used for Chinese characters is GBK. The idea is, 128 extra characters, ...
Read more >Match regular expression (case sensitive) - MATLAB regexp
This MATLAB function returns the starting index of each substring of str that matches the character patterns specified by the regular expression.
Read more >Simplified Chinese Character Set
Data Type Mapping Between Uniface and JavaScript ... Restrictions on Use of Unicode and Installable Character Sets ... Expressions in an Output Sequence....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When you say “we need Chinese in JavaScript”, could you please help me understand why you need it? I mean, why having escaped output does not work for you? Of course I understand any character encoding can be used in an HTML document, but generally escaping operations are performed for security reasons and in order to avoid very common display issues. However, again, if there is a reason why your JavaScript literals cannot be escaped in your code, could you please explain this reason so that I can better understand the scenario?
Anyway, you can obtain unescaped output like this (using
[(...)]
):But please note that you need to take care of the quotes for yourself (
'...'
) and also of manually escaping any single quotes ('
) that might appear inside your literal in order to not break the literal.i knew the code is work. but it doesn’t friendly to developer.you cann’t see the strings of meaning. anyway, think you 👍