-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: execute adds blanks #5534
Labels
Comments
Labels changed: added priority-soon, removed priority-triage. Owner changed to @robpike. Status changed to Accepted. |
can't reproduce either. also can't reproduce the standalone test case: http://play.golang.org/p/W9Wpz0NLO1 |
Error is difficult to reproduce, and maybe it depends on the template. Source code in attachments. Attachments:
|
smaller standalone test: http://play.golang.org/p/bE7bMu73dG as the added blanks are in the scripts, is it a big deal? |
http://play.golang.org/p/x5VkIAyi3t is even shorter. It needs the javascript escaping, which means it's caused by javascript escaping. I'm not sure it's actually wrong and will find out. Status changed to Accepted. |
http://play.golang.org/p/-qdFFKF-kI minimal version. Оther scripts, too. In general, the scripting language is not known, so in my opinion it is necessary to give content <script></script> as is. |
That's intentional because x-{{-1}} should not lead to the token sequence "x" "--"(decrement) "1" instead of the probably intended "x" "-"(binary -) "-"(unary -) "1" Also the guarantee the IS escaping functions provide is http://golang.org/src/pkg/html/template/js.go#L133 133 // jsValEscaper escapes its inputs to a JS Expression (section 11.14) that has 134 // neither side-effects nor free variables outside (NaN, Infinity). and allowing token merging would mean that the simplest sub-expression into which an interpolation happens could have free variables not in (NaN, Infinity). It's done at http://golang.org/src/pkg/html/template/js.go#L183 183 // Prevent IdentifierNames and NumericLiterals from running into 184 // keywords: in, instanceof, typeof, void 185 pad := isJSIdentPart(first) || isJSIdentPart(last) 186 if pad { 187 buf.WriteByte(' ') 188 } If there's a strong use case for merged tokens then content.JS should allow a safety hatch. If the concern is over output-size, then it should be possible to determine whether the Most of the token merging cases shouldn't affect JS that is likely to appear in a template -- there are few places in a JS program where two identifiers/numbers can be adjacent; but there's some interest in TC39 for moving towards a less punctuation heavy syntax. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by Knyaginin:
The text was updated successfully, but these errors were encountered: