Skip to content

Commit

Permalink
Fix handle of space at start or last (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozraru committed Sep 14, 2023
1 parent a272670 commit 680ea24
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions decode_test.go
Expand Up @@ -67,6 +67,18 @@ func TestDecoder(t *testing.T) {
"v: 1.234\n",
map[string]string{"v": "1.234"},
},
{
"v: \" foo\"\n",
map[string]string{"v": " foo"},
},
{
"v: \"foo \"\n",
map[string]string{"v": "foo "},
},
{
"v: \" foo \"\n",
map[string]string{"v": " foo "},
},
{
"v: false\n",
map[string]bool{"v": false},
Expand Down
15 changes: 15 additions & 0 deletions encode_test.go
Expand Up @@ -303,6 +303,21 @@ func TestEncoder(t *testing.T) {
map[string]string{"a": "Hello #comment"},
nil,
},
{
"a: \" b\"\n",
map[string]string{"a": " b"},
nil,
},
{
"a: \"b \"\n",
map[string]string{"a": "b "},
nil,
},
{
"a: \" b \"\n",
map[string]string{"a": " b "},
nil,
},
{
"a: 100.5\n",
map[string]interface{}{
Expand Down
4 changes: 2 additions & 2 deletions token/token.go
Expand Up @@ -623,12 +623,12 @@ func IsNeedQuoted(value string) bool {
}
first := value[0]
switch first {
case '*', '&', '[', '{', '}', ']', ',', '!', '|', '>', '%', '\'', '"', '@':
case '*', '&', '[', '{', '}', ']', ',', '!', '|', '>', '%', '\'', '"', '@', ' ':
return true
}
last := value[len(value)-1]
switch last {
case ':':
case ':', ' ':
return true
}
if looksLikeTimeValue(value) {
Expand Down
3 changes: 3 additions & 0 deletions token/token_test.go
Expand Up @@ -118,6 +118,9 @@ func TestIsNeedQuoted(t *testing.T) {
"Off",
"OFF",
"@test",
" a",
" a ",
"a ",
}
for i, test := range needQuotedTests {
if !token.IsNeedQuoted(test) {
Expand Down

0 comments on commit 680ea24

Please sign in to comment.