]> Cypherpunks repositories - gostls13.git/commit
exp/template/html: make sure marshalled JSON can be parsed as JS.
authorMike Samuel <mikesamuel@gmail.com>
Mon, 26 Sep 2011 09:10:43 +0000 (02:10 -0700)
committerMike Samuel <mikesamuel@gmail.com>
Mon, 26 Sep 2011 09:10:43 +0000 (02:10 -0700)
commit10bf744772c0cfae8ea0e9f34adb7afec3d03a72
tree2c4fd7db1261fd3b86d035787c801c572e0dc63b
parent377141510005e1b6d67044f557f7367cccc7e659
exp/template/html: make sure marshalled JSON can be parsed as JS.

This makes sure that all JS newlines are encoded in JSON.

It also moots a TODO about possibly escaping supplemental codepoints.
I served:

Content-Type: text/javascript;charset=UTF-8

var s = "%s";
document.write("<p>", s, "</p><ol>");
for (var i = 0; i < s.length; i++) {
  document.write("<li>", s.charCodeAt(i).toString(16), "</li>");
}
document.write("</l>");

where %s was replaced with bytes "\xf0\x9d\x84\x9e" to test
straight UTF-8 instead of encoding surrogates separately.

Recent Firefox, Chrome, and Safari all decoded it properly.
I have yet to try it on IE or older versions.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5129042
src/pkg/exp/template/html/escape_test.go
src/pkg/exp/template/html/js.go
src/pkg/exp/template/html/js_test.go