Navigation Menu

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

encoding/json: U+2028 and U+2029 generate invalid JavaScript #5836

Closed
evmar opened this issue Jul 4, 2013 · 3 comments
Closed

encoding/json: U+2028 and U+2029 generate invalid JavaScript #5836

evmar opened this issue Jul 4, 2013 · 3 comments

Comments

@evmar
Copy link

evmar commented Jul 4, 2013

The basic problem is that U+2028 and U+2029 are invalid in a JavaScript string literal,
which means you must encode them as the six-character literals like "\u2028"
when generating JSON.  This post discusses further how JSON is not a subset of
JavaScript:
https://medium.com/joys-of-javascript/42a28471221d

This code snippet demonstrates the problem.  When I paste the printed snippet into
Chrome's JavaScript console I get an invalid token error.
http://play.golang.org/p/cs_I0Az8cI

PS: it's not really's Go's problem that the (valid) JSON it generates is not parseable
as JavaScript.  But encoding/json already does some not-required-by-JSON encoding (the
way it HTML-escaping angle brackets), so it seems silly to not encode these rare
characters as well; might as well do them as part of HTML-escaping.


$ go version
go version devel +7e6f9b9091c4 Wed Jun 19 09:44:40 2013 -0700 linux/amd64
@robpike
Copy link
Contributor

robpike commented Jul 4, 2013

Comment 1:

Labels changed: added priority-later, removed priority-triage.

Owner changed to @dsymonds.

Status changed to Accepted.

@dsymonds
Copy link
Contributor

dsymonds commented Jul 4, 2013

Comment 2:

Labels changed: added packagebug, security.

Status changed to Started.

@dsymonds
Copy link
Contributor

Comment 3:

This issue was closed by revision d754647.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants