Skip to content

Commit

Permalink
Merge pull request #133 from goccy/feature/fix-recursive-alias
Browse files Browse the repository at this point in the history
Fix recursive alias in UnmarshalBytes
  • Loading branch information
goccy authored Jun 15, 2020
2 parents 24a3c7e + 597cf26 commit 1c5a6a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (d *Decoder) resolveAlias(node ast.Node) ast.Node {
}
case *ast.AliasNode:
aliasName := n.Value.GetToken().Value
return d.anchorNodeMap[aliasName]
return d.resolveAlias(d.anchorNodeMap[aliasName])
}
return node
}
Expand Down
12 changes: 11 additions & 1 deletion decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,7 @@ anchors:
map: &y
a: b
c: d
d: *x
a: *x
b:
<<: *y
Expand All @@ -1920,7 +1921,16 @@ b:
if v.A != "hello" {
t.Fatal("failed to unmarshal with alias")
}
if len(v.B) != 3 {
if len(v.B) != 4 {
t.Fatal("failed to unmarshal with alias")
}
if v.B["a"] != "b" {
t.Fatal("failed to unmarshal with alias")
}
if v.B["c"] != "d" {
t.Fatal("failed to unmarshal with alias")
}
if v.B["d"] != "hello" {
t.Fatal("failed to unmarshal with alias")
}
}

0 comments on commit 1c5a6a5

Please sign in to comment.