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:
parent
a03900a12f
commit
3b1b840699
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user