Skip to content

Commit 89a6600

Browse files
authored
Fix encoding of string that contains "- " (#657)
* fix encoding of string that contains "- " * fix test case
1 parent 2ac8cff commit 89a6600

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

encode_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestEncoder(t *testing.T) {
171171
},
172172
},
173173
{
174-
"a: -\n",
174+
"a: \"-\"\n",
175175
map[string]string{"a": "-"},
176176
nil,
177177
},

token/token.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ func IsNeedQuoted(value string) bool {
679679
if isNumber(value) {
680680
return true
681681
}
682+
if value == "-" {
683+
return true
684+
}
682685
first := value[0]
683686
switch first {
684687
case '*', '&', '[', '{', '}', ']', ',', '!', '|', '>', '%', '\'', '"', '@', ' ', '`':
@@ -696,7 +699,7 @@ func IsNeedQuoted(value string) bool {
696699
switch c {
697700
case '#', '\\':
698701
return true
699-
case ':':
702+
case ':', '-':
700703
if i+1 < len(value) && value[i+1] == ' ' {
701704
return true
702705
}

token/token_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func TestIsNeedQuoted(t *testing.T) {
133133
"Null",
134134
"NULL",
135135
"~",
136+
"-",
137+
"- --foo",
136138
}
137139
for i, test := range needQuotedTests {
138140
if !token.IsNeedQuoted(test) {

0 commit comments

Comments
 (0)