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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3724,3 +3724,23 @@ func TestSetNullValue(t *testing.T) {
})
}
}

func TestBackslash(t *testing.T) {
yml := `
test:
path: C:\Users\foo
`
type Test struct {
Path string `yaml:"path"`
}
type Value struct {
Test Test `yaml:"test"`
}
var v Value
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
t.Fatal(err)
}
if v.Test.Path != "C:\\Users\\foo" {
t.Fatalf("path: unexpected value %s", v.Test.Path)
}
}
9 changes: 1 addition & 8 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestEncoder(t *testing.T) {
nil,
},
{
"a: \"\\\\0\"\n",
"a: \\0\n",
map[string]string{"a": "\\0"},
nil,
},
Expand Down Expand Up @@ -781,13 +781,6 @@ func TestEncoder(t *testing.T) {
yaml.UseSingleQuote(false),
},
},
{
`a: '\.yaml'` + "\n",
map[string]string{"a": `\.yaml`},
[]yaml.EncodeOption{
yaml.UseSingleQuote(true),
},
},
}
for _, test := range tests {
t.Run(test.source, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func IsNeedQuoted(value string) bool {
}
for i, c := range value {
switch c {
case '#', '\\':
case '#':
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment here to explain why the backslash no longer triggers the need to quote the string, clarifying that this change supports system-dependent paths.

Copilot uses AI. Check for mistakes.
return true
case ':', '-':
if i+1 < len(value) && value[i+1] == ' ' {
Expand Down
1 change: 0 additions & 1 deletion token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func TestIsNeedQuoted(t *testing.T) {
"2001-12-15 2:59:43.10",
"2002-12-14",
"hoge # comment",
"\\0",
"#a b",
"*a b",
"&a b",
Expand Down