Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
5edeef21
Commit
5edeef21
authored
Sep 02, 2011
by
Mike Samuel
Committed by
Nigel Tao
Sep 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/template/html: non-semantics changing tweaks to js{,_test}.go
R=nigeltao CC=golang-dev
https://golang.org/cl/4962049
parent
3fa7226d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
js.go
src/pkg/exp/template/html/js.go
+2
-4
js_test.go
src/pkg/exp/template/html/js_test.go
+7
-3
No files found.
src/pkg/exp/template/html/js.go
View file @
5edeef21
...
@@ -179,7 +179,6 @@ func jsStrEscaper(args ...interface{}) string {
...
@@ -179,7 +179,6 @@ func jsStrEscaper(args ...interface{}) string {
for
i
,
r
:=
range
s
{
for
i
,
r
:=
range
s
{
var
repl
string
var
repl
string
switch
r
{
switch
r
{
// All cases must appear in the IndexAny call above.
case
0
:
case
0
:
repl
=
`\0`
repl
=
`\0`
case
'\t'
:
case
'\t'
:
...
@@ -222,7 +221,7 @@ func jsStrEscaper(args ...interface{}) string {
...
@@ -222,7 +221,7 @@ func jsStrEscaper(args ...interface{}) string {
b
.
WriteString
(
repl
)
b
.
WriteString
(
repl
)
written
=
i
+
utf8
.
RuneLen
(
r
)
written
=
i
+
utf8
.
RuneLen
(
r
)
}
}
if
b
.
Len
()
==
0
{
if
written
==
0
{
return
s
return
s
}
}
b
.
WriteString
(
s
[
written
:
])
b
.
WriteString
(
s
[
written
:
])
...
@@ -247,7 +246,6 @@ func jsRegexpEscaper(args ...interface{}) string {
...
@@ -247,7 +246,6 @@ func jsRegexpEscaper(args ...interface{}) string {
for
i
,
r
:=
range
s
{
for
i
,
r
:=
range
s
{
var
repl
string
var
repl
string
switch
r
{
switch
r
{
// All cases must appear in the IndexAny call above.
case
0
:
case
0
:
repl
=
`\0`
repl
=
`\0`
case
'\t'
:
case
'\t'
:
...
@@ -316,7 +314,7 @@ func jsRegexpEscaper(args ...interface{}) string {
...
@@ -316,7 +314,7 @@ func jsRegexpEscaper(args ...interface{}) string {
b
.
WriteString
(
repl
)
b
.
WriteString
(
repl
)
written
=
i
+
utf8
.
RuneLen
(
r
)
written
=
i
+
utf8
.
RuneLen
(
r
)
}
}
if
b
.
Len
()
==
0
{
if
written
==
0
{
return
s
return
s
}
}
b
.
WriteString
(
s
[
written
:
])
b
.
WriteString
(
s
[
written
:
])
...
...
src/pkg/exp/template/html/js_test.go
View file @
5edeef21
...
@@ -46,7 +46,7 @@ func TestNextJsCtx(t *testing.T) {
...
@@ -46,7 +46,7 @@ func TestNextJsCtx(t *testing.T) {
{
jsCtxRegexp
,
"+"
},
{
jsCtxRegexp
,
"+"
},
{
jsCtxRegexp
,
"-"
},
{
jsCtxRegexp
,
"-"
},
// An incr/decr op precedes a div operator.
// An incr/decr op precedes a div operator.
// This is not airtight.
In (g = ++/h/i) a regexp follows a
// This is not airtight. In (g = ++/h/i) a regexp follows a
// pre-increment operator, but in practice devs do not try to
// pre-increment operator, but in practice devs do not try to
// increment or decrement regular expressions.
// increment or decrement regular expressions.
// (g++/h/i) where ++ is a postfix operator on g is much more
// (g++/h/i) where ++ is a postfix operator on g is much more
...
@@ -66,7 +66,7 @@ func TestNextJsCtx(t *testing.T) {
...
@@ -66,7 +66,7 @@ func TestNextJsCtx(t *testing.T) {
{
jsCtxRegexp
,
"return
\n
"
},
{
jsCtxRegexp
,
"return
\n
"
},
{
jsCtxRegexp
,
"return
\u2028
"
},
{
jsCtxRegexp
,
"return
\u2028
"
},
// Identifiers can be divided and cannot validly be preceded by
// Identifiers can be divided and cannot validly be preceded by
// a regular expressions.
Semicolon insertion cannot happen
// a regular expressions. Semicolon insertion cannot happen
// between an identifier and a regular expression on a new line
// between an identifier and a regular expression on a new line
// because the one token lookahead for semicolon insertion has
// because the one token lookahead for semicolon insertion has
// to conclude that it could be a div binary op and treat it as
// to conclude that it could be a div binary op and treat it as
...
@@ -136,7 +136,7 @@ func TestJSValEscaper(t *testing.T) {
...
@@ -136,7 +136,7 @@ func TestJSValEscaper(t *testing.T) {
{
""
,
`""`
},
{
""
,
`""`
},
{
"foo"
,
`"foo"`
},
{
"foo"
,
`"foo"`
},
// Newlines.
// Newlines.
// {"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`}, // TODO: FAILING.
Maybe fix in json package.
// {"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`}, // TODO: FAILING. Maybe fix in json package.
// "\v" == "v" on IE 6 so use "\x0b" instead.
// "\v" == "v" on IE 6 so use "\x0b" instead.
{
"
\t\x0b
"
,
`"\u0009\u000b"`
},
{
"
\t\x0b
"
,
`"\u0009\u000b"`
},
{
struct
{
X
,
Y
int
}{
1
,
2
},
`{"X":1,"Y":2}`
},
{
struct
{
X
,
Y
int
}{
1
,
2
},
`{"X":1,"Y":2}`
},
...
@@ -205,6 +205,10 @@ func TestJSStrEscaper(t *testing.T) {
...
@@ -205,6 +205,10 @@ func TestJSStrEscaper(t *testing.T) {
{
"+ADw-script+AD4-alert(1)+ADw-/script+AD4-"
,
{
"+ADw-script+AD4-alert(1)+ADw-/script+AD4-"
,
`\x2bADw-script\x2bAD4-alert(1)\x2bADw-\/script\x2bAD4-`
,
`\x2bADw-script\x2bAD4-alert(1)\x2bADw-\/script\x2bAD4-`
,
},
},
// Invalid UTF-8 sequence
{
"foo
\xA0
bar"
,
"foo
\xA0
bar"
},
// Invalid unicode scalar value.
{
"foo
\xed\xa0\x80
bar"
,
"foo
\xed\xa0\x80
bar"
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment