]> Cypherpunks repositories - gostls13.git/commitdiff
exp/template/html: fix bug /*/ is not a full JS block comment.
authorMike Samuel <mikesamuel@gmail.com>
Mon, 12 Sep 2011 23:01:30 +0000 (16:01 -0700)
committerMike Samuel <mikesamuel@gmail.com>
Mon, 12 Sep 2011 23:01:30 +0000 (16:01 -0700)
Similar tests for CSS already catch this problem in tCSS.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4967065

src/pkg/exp/template/html/escape.go
src/pkg/exp/template/html/escape_test.go

index d3c06bb7f6334e6a62cc133cace5ba0991ea0830..955b41be22307a6dd38d360e28c46d38526ab000 100644 (file)
@@ -487,9 +487,9 @@ func tJS(c context, s []byte) (context, []byte) {
        case '/':
                switch {
                case i+1 < len(s) && s[i+1] == '/':
-                       c.state = stateJSLineCmt
+                       c.state, i = stateJSLineCmt, i+1
                case i+1 < len(s) && s[i+1] == '*':
-                       c.state = stateJSBlockCmt
+                       c.state, i = stateJSBlockCmt, i+1
                case c.jsCtx == jsCtxRegexp:
                        c.state = stateJSRegexp
                default:
index 23f573498776b1ead84a98030d619c9893a372c9..488f33a4add71fb59d13ceae861fcf1922d50429 100644 (file)
@@ -643,6 +643,14 @@ func TestEscapeText(t *testing.T) {
                        `<a onclick="/*`,
                        context{state: stateJSBlockCmt, delim: delimDoubleQuote},
                },
+               {
+                       `<a onclick="/*/`,
+                       context{state: stateJSBlockCmt, delim: delimDoubleQuote},
+               },
+               {
+                       `<a onclick="/**/`,
+                       context{state: stateJS, delim: delimDoubleQuote},
+               },
                {
                        `<a onkeypress="&quot;`,
                        context{state: stateJSDqStr, delim: delimDoubleQuote},