Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit eeec332

Browse files
committed
fix: decode !!binary as []byte
When decoding !!binary do not assume that the result will be a string, as !!binary can be use to encode arbitrary data.
1 parent f6f7691 commit eeec332

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (d *decoder) scalar(n *Node, out reflect.Value) bool {
575575
if err != nil {
576576
failf("!!binary value contains invalid base64 data")
577577
}
578-
resolved = string(data)
578+
resolved = data
579579
}
580580
}
581581
if resolved == nil {

decode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,13 @@ var unmarshalTests = []struct {
633633
// Binary data.
634634
{
635635
"a: !!binary gIGC\n",
636-
map[string]string{"a": "\x80\x81\x82"},
636+
map[string][]byte{"a": []byte{0x80, 0x81, 0x82}},
637637
}, {
638638
"a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
639-
map[string]string{"a": strings.Repeat("\x90", 54)},
639+
map[string][]byte{"a": bytes.Repeat([]byte{0x90}, 54)},
640640
}, {
641641
"a: !!binary |\n " + strings.Repeat("A", 70) + "\n ==\n",
642-
map[string]string{"a": strings.Repeat("\x00", 52)},
642+
map[string][]byte{"a": bytes.Repeat([]byte{0x00}, 52)},
643643
},
644644

645645
// Issue #39.

node_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,15 +2689,7 @@ var setStringTests = []struct {
26892689
Tag: "!!str",
26902690
Style: yaml.LiteralStyle,
26912691
},
2692-
}, {
2693-
"\x80\x81\x82",
2694-
"!!binary gIGC\n",
2695-
yaml.Node{
2696-
Kind: yaml.ScalarNode,
2697-
Value: "gIGC",
2698-
Tag: "!!binary",
2699-
},
2700-
},
2692+
},
27012693
}
27022694

27032695
func (s *S) TestSetString(c *C) {

0 commit comments

Comments
 (0)