Skip to content

Fix/yamlmerger deep merge#2660

Open
Syedowais312 wants to merge 2 commits intounikraft:stagingfrom
Syedowais312:fix/yamlmerger-deep-merge
Open

Fix/yamlmerger deep merge#2660
Syedowais312 wants to merge 2 commits intounikraft:stagingfrom
Syedowais312:fix/yamlmerger-deep-merge

Conversation

@Syedowais312
Copy link

Summary

This PR fixes scalar node merge behavior in RecursiveMerge
by replacing pointer reassignment with value overwrite.

It also improves sequence merging by introducing deep
node comparison, enabling proper handling of sequences
of mappings and nested structures.

Changes

  • Fix scalar overwrite behavior
  • Implement recursive deep equality for sequences
  • Update and extend test coverage

Testing

All tests pass with:

go test ./internal/yamlmerger/...

Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
@Syedowais312 Syedowais312 force-pushed the fix/yamlmerger-deep-merge branch from 630fcdf to c8371e6 Compare February 24, 2026 19:47
case yaml.ScalarNode:
// SA4006 these variables represent pointers and are propagated outside of `recursiveMerge`
into = from //nolint:staticcheck
*into = *from
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this reassigned the local pointer (into = from), which did not modify the underlying node. Using *into = *from correctly overwrites the target node value.

foundFrom := false
for _, intoItem := range into.Content {
if fromItem.Value == intoItem.Value {
if nodesDeepEqual(fromItem, intoItem) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also replaced shallow .Value comparison with structural deep equality. .Value works for scalar nodes but fails for mappings and nested structures.

@nderjung @craciunoiuc could you please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🧊 Icebox

Development

Successfully merging this pull request may close these issues.

1 participant