Commit 3b1b8406 authored by Volker Dobler's avatar Volker Dobler Committed by Rob Pike

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
parent a03900a1
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment