diff options
Diffstat (limited to 'libgo/go/html/template/js.go')
-rw-r--r-- | libgo/go/html/template/js.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libgo/go/html/template/js.go b/libgo/go/html/template/js.go index 999a61ed078..f6d166b3113 100644 --- a/libgo/go/html/template/js.go +++ b/libgo/go/html/template/js.go @@ -246,8 +246,10 @@ func jsRegexpEscaper(args ...interface{}) string { // `\u2029`. func replace(s string, replacementTable []string) string { var b bytes.Buffer - written := 0 - for i, r := range s { + r, w, written := rune(0), 0, 0 + for i := 0; i < len(s); i += w { + // See comment in htmlEscaper. + r, w = utf8.DecodeRuneInString(s[i:]) var repl string switch { case int(r) < len(replacementTable) && replacementTable[r] != "": @@ -261,7 +263,7 @@ func replace(s string, replacementTable []string) string { } b.WriteString(s[written:i]) b.WriteString(repl) - written = i + utf8.RuneLen(r) + written = i + w } if written == 0 { return s |