Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
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
8 changes: 5 additions & 3 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,13 @@ func (e *encoder) node(node *Node, tail string) {
tag = ""
} else {
rtag, _ := resolve("", node.Value)
if rtag == stag {
if stag == strTag {
tag = ""
} else if stag == strTag {
if rtag != stag || isBase60Float(node.Value) || isOldBool(node.Value) {
forceQuoting = true
}
} else if stag == rtag {
tag = ""
forceQuoting = true
}
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,32 @@ var marshalTests = []struct {
},
"value: !!seq []\n",
},

// Enforced string nodes quoting with old-style booleans
{
&struct {
Value yaml.Node
}{
yaml.Node{
Kind: yaml.ScalarNode,
Value: "y",
Tag: "!!str",
},
},
"value: \"y\"\n",
},
{
&struct {
Value yaml.Node
}{
yaml.Node{
Kind: yaml.ScalarNode,
Value: "yes",
Tag: "!!str",
},
},
"value: \"yes\"\n",
},
}

func (s *S) TestMarshal(c *C) {
Expand Down