Repository navigation
fix: handle JsonArray nodes in setAtPath and deleteAtPath (RFC 6901 integer-index traversal) - #31
Open
himanshubakshi wants to merge 1 commit into
Conversation
…nteger-index traversal) Both setAtPath and deleteAtPath only handled JsonObject at intermediate path nodes. Any JsonArray at an intermediate segment fell into the else branch, silently clobbering it with an empty JsonObject (set) or leaving it unchanged (delete) — no exception, no log. Fixes the silent-clobber bug tracked in issue Contextable#30. - setAtPath: add JsonArray branch → setAtPathInArray (integer-index write with JsonNull padding for out-of-bounds indices) - deleteAtPath: add JsonArray branch → deleteAtPathInArray (integer-index removal; out-of-bounds and non-numeric segments are no-ops) - Both helpers: defensive isEmpty() guard mirrors getAtPath's existing pattern - 18 new tests covering: append, preserve, pad, overwrite, non-numeric guard, sparse gaps, sequential appends, full replace, nested writes, drain-to-empty, delete first/middle/last, OOB, nested field delete, primitive-intermediate Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #30
Summary
Two related bugs in
DataModelwhereJsonArraynodes at intermediate path segments were silently mishandled:1.
setAtPath— silent data loss on indexed writesAny
JsonArrayat an intermediate path node fell into theelsebranch, replacing it with an emptyJsonObjectand discarding the entire array. No exception, no log.2.
deleteAtPath— silent no-op on indexed deletesThe same blind spot:
deleteAtPathonly recursed intoJsonObject. AJsonArrayat an intermediate node caused the delete to silently do nothing.Both bugs share the same root cause: missing
JsonArraybranch in the respectivewhenblocks.getAtPathalready handles arrays correctly (integer-index traversal viaobj.getOrNull(index)) — this PR bringssetAtPathanddeleteAtPathto parity.Fix
Add a
JsonArraybranch to both functions, delegating to newsetAtPathInArrayanddeleteAtPathInArrayhelpers:setAtPathInArray: integer-index write withJsonNullpadding whenindex >= size, enabling writes at absolute indices beyond the current array bounds. Non-numeric segment → no-op (protocol error guard).deleteAtPathInArray: integer-index removal. Out-of-bounds index and non-numeric segment → no-op. Recurses into nestedJsonObjectelements for deeper paths.isEmpty()guard, mirroringgetAtPath's existing pattern.RFC 6901 reference
RFC 6901 §4 defines integer-index traversal for arrays:
Tests
18 new tests in
DataModelTestcovering both helpers:setAtPathInArray(8 tests): append at absolute index, element preservation,JsonNullpadding beyond bounds, overwrite existing element, non-numeric segment guard, sparse index gaps, sequential multi-page appends, full-array replace after appends, nested path write into existing element, nested path write into null slot, primitive-at-intermediate-node regression.deleteAtPathInArray(8 tests): remove middle/first/last element, out-of-bounds index, non-numeric segment, nested field delete inside element, drain array to empty, delete through object→array path, non-object array element guard.Test plan
:a2ui-4k:jvmTest— BUILD SUCCESSFUL, all tests pass