Skip to content

Commit

Permalink
Allow encoding Node by value (#673).
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Jan 7, 2021
1 parent c8046fb commit 749611f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
e.nodev(in)
return
case Node:
if !in.CanAddr() {
var n = reflect.New(in.Type()).Elem()
n.Set(in)
in = n
}
e.nodev(in.Addr())
return
case time.Time:
Expand Down
8 changes: 8 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ var marshalTests = []struct {
},
},
"value: 'foo'\n",
}, {
yaml.Node{
Kind: yaml.ScalarNode,
Tag: "!!str",
Value: "foo",
Style: yaml.SingleQuotedStyle,
},
"'foo'\n",
},

// Enforced tagging with shorthand notation (issue #616).
Expand Down

0 comments on commit 749611f

Please sign in to comment.