Delete the set of bytes that need quoting in TextHandler, because it
is almost identical to the set for JSON. Use JSONHandler's safeSet
with a few exceptions.
Updates #56345.
Change-Id: Iff6d309c067affef2e5ecfcebd6e1bb8f00f95b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/478198
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
for i := 0; i < len(s); {
b := s[i]
if b < utf8.RuneSelf {
- if needsQuotingSet[b] {
+ // Quote anything except a backslash that would need quoting in a
+ // JSON string, as well as space and '='
+ if b != '\\' && (b == ' ' || b == '=' || !safeSet[b]) {
return true
}
i++
}
return false
}
-
-var needsQuotingSet = [utf8.RuneSelf]bool{
- '"': true,
- '=': true,
-}
-
-func init() {
- for i := 0; i < utf8.RuneSelf; i++ {
- r := rune(i)
- if unicode.IsSpace(r) || !unicode.IsPrint(r) {
- needsQuotingSet[i] = true
- }
- }
-}