diff --git a/encode_test.go b/encode_test.go index b4f3913c..be377c4d 100644 --- a/encode_test.go +++ b/encode_test.go @@ -171,7 +171,7 @@ func TestEncoder(t *testing.T) { }, }, { - "a: -\n", + "a: \"-\"\n", map[string]string{"a": "-"}, nil, }, diff --git a/token/token.go b/token/token.go index 54ab1799..4fe300f8 100644 --- a/token/token.go +++ b/token/token.go @@ -679,6 +679,9 @@ func IsNeedQuoted(value string) bool { if isNumber(value) { return true } + if value == "-" { + return true + } first := value[0] switch first { case '*', '&', '[', '{', '}', ']', ',', '!', '|', '>', '%', '\'', '"', '@', ' ', '`': @@ -696,7 +699,7 @@ func IsNeedQuoted(value string) bool { switch c { case '#', '\\': return true - case ':': + case ':', '-': if i+1 < len(value) && value[i+1] == ' ' { return true } diff --git a/token/token_test.go b/token/token_test.go index 3b339b4b..489a5315 100644 --- a/token/token_test.go +++ b/token/token_test.go @@ -133,6 +133,8 @@ func TestIsNeedQuoted(t *testing.T) { "Null", "NULL", "~", + "-", + "- --foo", } for i, test := range needQuotedTests { if !token.IsNeedQuoted(test) {