mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-24 11:00:39 +00:00
improve escaping when colon in string
This commit is contained in:
parent
3ea0d8d8ec
commit
2a45c1c328
@ -65,7 +65,7 @@ func isZero(v interface{}) bool {
|
|||||||
|
|
||||||
func isQuoted(b rune) bool {
|
func isQuoted(b rune) bool {
|
||||||
switch b {
|
switch b {
|
||||||
case ':', '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`':
|
case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`':
|
||||||
return true
|
return true
|
||||||
case '\a', '\b', '\f', '\n', '\r', '\t', '\v':
|
case '\a', '\b', '\f', '\n', '\r', '\t', '\v':
|
||||||
return true
|
return true
|
||||||
|
@ -195,11 +195,17 @@ func writeEncode(w writer, v string) {
|
|||||||
w.WriteByte('"')
|
w.WriteByte('"')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var prev rune
|
||||||
for _, b := range v {
|
for _, b := range v {
|
||||||
if isQuoted(b) {
|
if isQuoted(b) {
|
||||||
fmt.Fprintf(w, "%q", v)
|
fmt.Fprintf(w, "%q", v)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if b == ' ' && prev == ':' {
|
||||||
|
fmt.Fprintf(w, "%q", v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prev = b
|
||||||
}
|
}
|
||||||
w.WriteString(v)
|
w.WriteString(v)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user