Skip to content

Commit

Permalink
Fix encoding explicitly marked str nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
torkve committed Oct 3, 2024
1 parent f6f7691 commit 7915b2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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

0 comments on commit 7915b2a

Please sign in to comment.