]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: CanBackquote should reject \x7F
authorRob Pike <r@golang.org>
Tue, 18 Mar 2014 23:16:48 +0000 (10:16 +1100)
committerRob Pike <r@golang.org>
Tue, 18 Mar 2014 23:16:48 +0000 (10:16 +1100)
It's a control character.
Fixes #7565.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/77300043

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

index 7d6cdcf0b54985ce3133556be18500bab4db8da3..aded7e5930c329992c1ed3b865e48d5bb2f5accc 100644 (file)
@@ -144,7 +144,8 @@ func AppendQuoteRuneToASCII(dst []byte, r rune) []byte {
 // characters other than space and tab.
 func CanBackquote(s string) bool {
        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
                }
        }
index 61d9bf9a571428e351bb4cdde9689f45dd17f7fc..e4b5b6b9fd2d0d2fb9e05ba5f9e1ba589d5b8458 100644 (file)
@@ -140,6 +140,7 @@ var canbackquotetests = []canBackquoteTest{
        {string(29), false},
        {string(30), false},
        {string(31), false},
+       {string(0x7F), false},
        {`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true},
        {`0123456789`, true},
        {`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true},