Skip to content

fix: copy all Differ options in structValues to preserve TagName#120

Open
Yanhu007 wants to merge 1 commit intor3labs:masterfrom
Yanhu007:fix/struct-values-copy-tag-name
Open

fix: copy all Differ options in structValues to preserve TagName#120
Yanhu007 wants to merge 1 commit intor3labs:masterfrom
Yanhu007:fix/struct-values-copy-tag-name

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #117

Problem

structValues creates a new Differ for recursive diffing but only copies Filter and customValueDiffers. All other configuration fields — notably TagName, SliceOrdering, FlattenEmbeddedStructs, etc. — are lost.

This means when diffing nested or embedded structs via CREATE/DELETE paths, tag names are ignored and raw field names are used instead.

type A struct {
    Field1 struct {
        Field2 string `diff:"F1"`
    } `diff:"F2"`
}
// Expected path: ["F2", "F1"]
// Actual path:   ["F2", "Field2"]  (F1 tag lost in nested struct)

Fix

Copy all Differ configuration fields when creating the nested instance in structValues, using a struct literal instead of zero-value + selective assignment.

All existing tests pass.

…other settings

structValues creates a new Differ (nd) for recursive value
diffing but only copied Filter and customValueDiffers. This
caused TagName and all other configuration options (SliceOrdering,
FlattenEmbeddedStructs, etc.) to be lost when diffing nested/
embedded structs, falling back to field names instead of tag names.

Copy all Differ configuration fields when creating the nested
Differ instance.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diffing embedded structs and slices causes the tag name to be lost.

1 participant