Commit f34251a9 authored by Rob Pike's avatar Rob Pike

strconv: CanBackquote should reject \x7F

It's a control character.
Fixes #7565.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/77300043
parent f081e2b9
...@@ -144,7 +144,8 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte { ...@@ -144,7 +144,8 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte {
// characters other than space and tab. // characters other than space and tab.
func CanBackquote(s string) bool { func CanBackquote(s string) bool {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
if (s[i] < ' ' && s[i] != '\t') || s[i] == '`' { c := s[i]
if (c < ' ' && c != '\t') || c == '`' || c == '\u007F' {
return false return false
} }
} }
......
...@@ -140,6 +140,7 @@ var canbackquotetests = []canBackquoteTest{ ...@@ -140,6 +140,7 @@ var canbackquotetests = []canBackquoteTest{
{string(29), false}, {string(29), false},
{string(30), false}, {string(30), false},
{string(31), false}, {string(31), false},
{string(0x7F), false},
{`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true}, {`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true},
{`0123456789`, true}, {`0123456789`, true},
{`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true}, {`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true},
......
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