question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using javascript inline expression in a Chinese character set

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
danielfernandezcommented, Nov 6, 2017

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 [(...)]):

<script th:inline="javascript">
var user = '[(${sessCtx.username})]';
</script>

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.

0reactions
mangodaicommented, Nov 6, 2017

i knew the code is work. but it doesn’t friendly to developer.you cann’t see the strings of meaning. anyway, think you 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found