1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:40:03 -07:00

strconv: fix handling of BOMs in CanBackquote

A byte order mark  (BOM) cannot be backquoted.

LGTM=r
R=golang-codereviews, gobot, r
CC=golang-codereviews
https://golang.org/cl/112310043
This commit is contained in:
Volker Dobler 2014-07-16 13:06:11 -07:00 committed by Rob Pike
parent a03900a12f
commit 3b1b840699
2 changed files with 6 additions and 3 deletions

View File

@ -147,7 +147,10 @@ func CanBackquote(s string) bool {
r, wid := utf8.DecodeRuneInString(s)
s = s[wid:]
if wid > 1 {
continue // All multibyte runes are correctly encoded and assumed printable.
if r == '\ufeff' {
return false // BOMs are invisible and should not be quoted.
}
continue // All other multibyte runes are correctly encoded and assumed printable.
}
if r == utf8.RuneError {
return false

View File

@ -148,8 +148,8 @@ var canbackquotetests = []canBackquoteTest{
{``, true},
{"\x80", false},
{"a\xe0\xa0z", false},
{"\ufeffabc", true},
{"a\ufeffz", true},
{"\ufeffabc", false},
{"a\ufeffz", false},
}
func TestCanBackquote(t *testing.T) {