Preserve nested values on parent path conflicts
All checks were successful
CI / test (pull_request) Successful in 9s

This commit is contained in:
2026-07-19 10:06:49 +09:00
parent 2e96d174f2
commit 3edb93fcf7
2 changed files with 24 additions and 7 deletions

View File

@@ -138,12 +138,24 @@ func TestParseCellConservativeInference(t *testing.T) {
}
func TestSetPathDoesNotOverwriteConflictingShape(t *testing.T) {
t.Run("parent scalar before child", func(t *testing.T) {
record := map[string]any{}
setPath(record, "user", "Alice")
setPath(record, "user.name", "Bob")
if got := record["user"]; got != "Alice" {
t.Fatalf("user = %#v, want original scalar", got)
}
})
t.Run("child before parent scalar", func(t *testing.T) {
record := map[string]any{}
setPath(record, "user.name", "Bob")
setPath(record, "user", "Alice")
want := map[string]any{"name": "Bob"}
if got := record["user"]; !reflect.DeepEqual(got, want) {
t.Fatalf("user = %#v, want original nested value %#v", got, want)
}
})
}
func TestSetPathRestoresNestedArrays(t *testing.T) {

View File

@@ -93,7 +93,12 @@ func setPath(root map[string]any, path string, value any) {
return
}
if last {
// Preserve the value established by an earlier column. This also
// protects a nested map/slice when a later parent scalar conflicts
// with it (for example, user.name followed by user).
if _, exists := m[token.key]; !exists {
m[token.key] = value
}
return
}
if _, exists := m[token.key]; !exists {