]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: fix handling of BOMs in CanBackquote
authorVolker Dobler <dr.volker.dobler@gmail.com>
Wed, 16 Jul 2014 20:06:11 +0000 (13:06 -0700)
committerRob Pike <r@golang.org>
Wed, 16 Jul 2014 20:06:11 +0000 (13:06 -0700)
A byte order mark  (BOM) cannot be backquoted.

LGTM=r
R=golang-codereviews, gobot, r
CC=golang-codereviews
https://golang.org/cl/112310043

src/pkg/strconv/quote.go
src/pkg/strconv/quote_test.go

index 89dda997504c1ef383f28f4c9172e289702cbb73..8cdfc472f352303386d04e096733ccc1d9816a05 100644 (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
index 24998191d7b1fd568e03b1b4dcc8b4f783773918..3bf162f987e7878e57602d3a34923a0095e6c82c 100644 (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) {