-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle non-merge aliasing #416
Conversation
break | ||
} | ||
|
||
keyNode, valueNode, content = content[0], content[1], content[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to merge the content of the alias into the current content of the map, I found it easiest to turn this into a queue rather than trying to manipulate the index.
@@ -98,12 +98,16 @@ key2: value6 | |||
}) | |||
|
|||
t.Run("YamlAliases", func(t *testing.T) { | |||
b := []byte(`foo: &foo | |||
b := []byte(`foo: &foofoo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The anchor and the key do not need to have the same value. This makes sure we don't actually use the anchor value for anything.
bar: 1 | ||
baz: "baz" | ||
baz: &baz "baz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a top-level anchor, I used one inside a map to make sure this case is also covered.
bar: 0 | ||
<<: *foofoo | ||
baz: "bazbaz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure that the *foofoo
dereferencing
- overrides the
bar: 0
value - does not override the
baz: "bazbaz"
value
<<: *foofoo | ||
baz: "bazbaz" | ||
|
||
baz: *baz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a test for regular dereferencing.
Set("foo", dencoding.NewMap(). | ||
Set("bar", int64(1)). | ||
Set("baz", "baz")). | ||
Set("spam", dencoding.NewMap(). | ||
Set("ham", "eggs"). | ||
Set("bar", int64(1)). | ||
Set("baz", "bazbaz")). | ||
Set("baz", "baz") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new override tests, I found it easiest to not use the fooMap
and rather be explicit about the result.
Thanks for picking this up @pmeier, I'll release it under |
@TomWright my patch in #415 is incorrect and is missing a piece:
Regular alias dereferencing, e.g.
foo: *bar
was not handled, only merging an alias into a map.Merging an alias into a map is incorrect in add support for resolving YAML aliases #415 as it should only merge the children of the aliased map rather then the aliased map itself. For example,
currently decodes into
but should decode into