improve escaping when colon in string

This commit is contained in:
Brad Rydzewski 2019-05-29 19:13:32 -07:00
parent 3ea0d8d8ec
commit 2a45c1c328
2 changed files with 7 additions and 1 deletions

View File

@ -65,7 +65,7 @@ func isZero(v interface{}) bool {
func isQuoted(b rune) bool {
switch b {
case ':', '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`':
case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`':
return true
case '\a', '\b', '\f', '\n', '\r', '\t', '\v':
return true

View File

@ -195,11 +195,17 @@ func writeEncode(w writer, v string) {
w.WriteByte('"')
return
}
var prev rune
for _, b := range v {
if isQuoted(b) {
fmt.Fprintf(w, "%q", v)
return
}
if b == ' ' && prev == ':' {
fmt.Fprintf(w, "%q", v)
return
}
prev = b
}
w.WriteString(v)
}