From f34251a91c2d075def51b763c52a0c602f3e09c9 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 19 Mar 2014 10:16:48 +1100 Subject: [PATCH] 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 --- src/pkg/strconv/quote.go | 3 ++- src/pkg/strconv/quote_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/strconv/quote.go b/src/pkg/strconv/quote.go index 7d6cdcf0b5..aded7e5930 100644 --- a/src/pkg/strconv/quote.go +++ b/src/pkg/strconv/quote.go @@ -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 } } diff --git a/src/pkg/strconv/quote_test.go b/src/pkg/strconv/quote_test.go index 61d9bf9a57..e4b5b6b9fd 100644 --- a/src/pkg/strconv/quote_test.go +++ b/src/pkg/strconv/quote_test.go @@ -140,6 +140,7 @@ var canbackquotetests = []canBackquoteTest{ {string(29), false}, {string(30), false}, {string(31), false}, + {string(0x7F), false}, {`' !"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, true}, {`0123456789`, true}, {`ABCDEFGHIJKLMNOPQRSTUVWXYZ`, true}, -- 2.51.0