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
html/template: inconsistent JSON output behavior #38895
Comments
I further confirmed that this problem happens when backtick string is used in javascript. i.e. if I change the above line to:
the problem is gone. However, I need to use template string in JS. This should be fixed in Go's template engine. |
final confirmation: if the declaration is before statement with backtick, this problem does not exist. i.e. BUGGY:
FINE:
|
From mvdan on 29406:
It might be that Go has never supported using backticks in templates and if you do use them, instead of throwing an error the behavior is undefined. If my understanding of this is correct, this issue is a duplicate of #9200 and your immediate resolution is to stop using backticks in your templates. |
Please note my last comment, the problem is related to the location of {{.}} and the backtick. @Gregory-Ledray |
/cc @mikesamuel @empijei |
I confirm this is a duplicate of #9200. We should try to get that addressed but it is not a trivial change and it is quite hard to find a solution that would satisfy all current users. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In Go:
In "chkin.html":
What did you expect to see?
I expect the JS code at
var data = {{.}}
is valid json format data, i.e.What did you see instead?
The template engine generated the following:
I noticed that the culprit is the following JS code in the function:
If this line is removed,
{{.}}
is correctly encoded into JSON.The text was updated successfully, but these errors were encountered: