mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-28 04:40:36 +00:00
improve escaping
This commit is contained in:
parent
2a45c1c328
commit
507291b915
@ -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
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/drone-yaml/yaml"
|
"github.com/drone/drone-yaml/yaml"
|
||||||
)
|
)
|
||||||
@ -195,6 +196,15 @@ func writeEncode(w writer, v string) {
|
|||||||
w.WriteByte('"')
|
w.WriteByte('"')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
trimmed := strings.TrimSpace(v)
|
||||||
|
if strings.HasPrefix(trimmed, "| ") {
|
||||||
|
fmt.Fprintf(w, "%q", v)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(trimmed, "> ") {
|
||||||
|
fmt.Fprintf(w, "%q", v)
|
||||||
|
return
|
||||||
|
}
|
||||||
var prev rune
|
var prev rune
|
||||||
for _, b := range v {
|
for _, b := range v {
|
||||||
if isQuoted(b) {
|
if isQuoted(b) {
|
||||||
|
Loading…
Reference in New Issue
Block a user