mirror of
https://github.com/golang/go
synced 2024-11-24 21:00:09 -07:00
exp/template/html: non-semantics changing tweaks to js{,_test}.go
R=nigeltao CC=golang-dev https://golang.org/cl/4962049
This commit is contained in:
parent
3fa7226de7
commit
5edeef214d
@ -179,7 +179,6 @@ func jsStrEscaper(args ...interface{}) string {
|
||||
for i, r := range s {
|
||||
var repl string
|
||||
switch r {
|
||||
// All cases must appear in the IndexAny call above.
|
||||
case 0:
|
||||
repl = `\0`
|
||||
case '\t':
|
||||
@ -222,7 +221,7 @@ func jsStrEscaper(args ...interface{}) string {
|
||||
b.WriteString(repl)
|
||||
written = i + utf8.RuneLen(r)
|
||||
}
|
||||
if b.Len() == 0 {
|
||||
if written == 0 {
|
||||
return s
|
||||
}
|
||||
b.WriteString(s[written:])
|
||||
@ -247,7 +246,6 @@ func jsRegexpEscaper(args ...interface{}) string {
|
||||
for i, r := range s {
|
||||
var repl string
|
||||
switch r {
|
||||
// All cases must appear in the IndexAny call above.
|
||||
case 0:
|
||||
repl = `\0`
|
||||
case '\t':
|
||||
@ -316,7 +314,7 @@ func jsRegexpEscaper(args ...interface{}) string {
|
||||
b.WriteString(repl)
|
||||
written = i + utf8.RuneLen(r)
|
||||
}
|
||||
if b.Len() == 0 {
|
||||
if written == 0 {
|
||||
return s
|
||||
}
|
||||
b.WriteString(s[written:])
|
||||
|
@ -205,6 +205,10 @@ func TestJSStrEscaper(t *testing.T) {
|
||||
{"+ADw-script+AD4-alert(1)+ADw-/script+AD4-",
|
||||
`\x2bADw-script\x2bAD4-alert(1)\x2bADw-\/script\x2bAD4-`,
|
||||
},
|
||||
// Invalid UTF-8 sequence
|
||||
{"foo\xA0bar", "foo\xA0bar"},
|
||||
// Invalid unicode scalar value.
|
||||
{"foo\xed\xa0\x80bar", "foo\xed\xa0\x80bar"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user