Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang unescape values in html templates | 东隅已逝/桑榆非晚 #46

Open
h1z3y3 opened this issue May 26, 2021 · 0 comments
Open

Comments

@h1z3y3
Copy link
Owner

h1z3y3 commented May 26, 2021

https://h1z3y3.me/posts/go-html-template-script-unescape/

While using values in a html template, my colleague faced a problem that the values in <script> tags are all escaped. So the template developer can not use the values in javascript. It just looks like this:
// ... <script type="text/json" id="channel" ch="recommend" tk=""> ["news","comedy","cartoon","tech","travelling","fashion","photograph","household","movies","foods","military","health","test"] </script> // ... I tried to find out the reason. So I copied the template values in other HTML tags rather than in <script>. It rendered correctly, and was not escaped:
// ...

["news","comedy","cartoon","tech","travelling","fashion","photograph","household","movies","foods","military","health","test"]
// ... First, I found some reasons like this, they said using json.Encoder rather than using json.Marshal() directly. So I can SetEscapeHTML(false).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant