Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(470)

Issue 5129042: code review 5129042: exp/template/html: make sure marshalled JSON can be par... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 5 months ago by MikeSamuel
Modified:
13 years, 5 months ago
Reviewers:
CC:
nigeltao, golang-dev
Visibility:
Public.

Description

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.

Patch Set 1 #

Patch Set 2 : diff -r 9fd69d51a3bd https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 9fd69d51a3bd https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 4 : diff -r 2c4ebd640b12 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 2c4ebd640b12 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+116 lines, -21 lines) Patch
M src/pkg/exp/template/html/escape_test.go View 1 2 3 5 chunks +27 lines, -2 lines 0 comments Download
M src/pkg/exp/template/html/js.go View 1 2 chunks +43 lines, -18 lines 0 comments Download
M src/pkg/exp/template/html/js_test.go View 1 2 chunks +46 lines, -1 line 0 comments Download

Messages

Total messages: 4
MikeSamuel
Hello nigeltao@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 5 months ago (2011-09-24 01:03:07 UTC) #1
nigeltao
LGTM. http://codereview.appspot.com/5129042/diff/3/src/pkg/exp/template/html/escape_test.go File src/pkg/exp/template/html/escape_test.go (right): http://codereview.appspot.com/5129042/diff/3/src/pkg/exp/template/html/escape_test.go#newcode21 src/pkg/exp/template/html/escape_test.go:21: return []byte("{ foo: 'not quite valid JSON' }"), ...
13 years, 5 months ago (2011-09-25 09:25:35 UTC) #2
MikeSamuel
http://codereview.appspot.com/5129042/diff/3/src/pkg/exp/template/html/escape_test.go File src/pkg/exp/template/html/escape_test.go (right): http://codereview.appspot.com/5129042/diff/3/src/pkg/exp/template/html/escape_test.go#newcode21 src/pkg/exp/template/html/escape_test.go:21: return []byte("{ foo: 'not quite valid JSON' }"), nil ...
13 years, 5 months ago (2011-09-26 09:10:18 UTC) #3
MikeSamuel
13 years, 5 months ago (2011-09-26 09:10:47 UTC) #4
*** Submitted as http://code.google.com/p/go/source/detail?r=51f8e9c7cb59 ***

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
http://codereview.appspot.com/5129042
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b