Skip to content

fix: append scalars when Set targets array index beyond length#286

Open
Solaris-star wants to merge 1 commit into
buger:masterfrom
Solaris-star:fix/267-set-array-index
Open

fix: append scalars when Set targets array index beyond length#286
Solaris-star wants to merge 1 commit into
buger:masterfrom
Solaris-star:fix/267-set-array-index

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

Set with successive array indexes on a newly created path overwrote the whole array instead of appending:

Set({}, 1, "test", "[0]") // {"test":[1]}
Set(..., 2, "test", "[1]") // was {"test":[2]}, want {"test":[1,2]}

Root cause: when extending an existing non-empty array, only arrays whose next token was { were treated as appendable. Scalar arrays took the overwrite branch.

Fix

Treat any non-empty array as extendable when the next key is an index ([n]), matching object-append behavior and issue #267.

Test plan

  • go test -run TestSet .
  • TestSetAppendsScalarToExistingArrayByIndex
  • updated supplemental coverage expectation to append (not overwrite)

Fixes #267

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.

Set with index overrides always first position of the array

1 participant