From: Volker Dobler Date: Wed, 16 Jul 2014 20:06:11 +0000 (-0700) Subject: strconv: fix handling of BOMs in CanBackquote X-Git-Tag: go1.4beta1~1085 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3b1b84069956bc8f21be37c563d0ba8da93a87d1;p=gostls13.git 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 --- diff --git a/src/pkg/strconv/quote.go b/src/pkg/strconv/quote.go index 89dda99750..8cdfc472f3 100644 --- a/src/pkg/strconv/quote.go +++ b/src/pkg/strconv/quote.go @@ -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 diff --git a/src/pkg/strconv/quote_test.go b/src/pkg/strconv/quote_test.go index 24998191d7..3bf162f987 100644 --- a/src/pkg/strconv/quote_test.go +++ b/src/pkg/strconv/quote_test.go @@ -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) {