Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestEncoder(t *testing.T) {
},
},
{
"a: -\n",
"a: \"-\"\n",
map[string]string{"a": "-"},
nil,
},
Expand Down
5 changes: 4 additions & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ func IsNeedQuoted(value string) bool {
if isNumber(value) {
return true
}
if value == "-" {
return true
}
first := value[0]
switch first {
case '*', '&', '[', '{', '}', ']', ',', '!', '|', '>', '%', '\'', '"', '@', ' ', '`':
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func TestIsNeedQuoted(t *testing.T) {
"Null",
"NULL",
"~",
"-",
"- --foo",
}
for i, test := range needQuotedTests {
if !token.IsNeedQuoted(test) {
Expand Down