Skip to content

Reject Patch add indexes past the end of an array - #55

Open
SashaMIT wants to merge 1 commit into
tailscale:masterfrom
SashaMIT:fix/patch-array-index
Open

SashaMIT wants to merge 1 commit into
tailscale:masterfrom
SashaMIT:fix/patch-array-index

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

Value.Patch treated an add whose array index was past the end as an append. find reports every missing index as the array length, so /5 on a two-element array wrote the value at the end. RFC 6902 section 4.1 requires an error in that case. An index equal to the length, and the - token, still append. The array is left unchanged when the index is past the end.

Fixes #52.

Test plan

  • go test -count=1 ./...
  • Before the check, adding at /5 on [1,2] returned no error and produced [1,2,3]. After the check, that call returns the out-of-range error and the array stays [1,2]. Restoring the old insert made that case fail again, and putting the check back passed it. An index equal to the length and the - token still append.

find reports every missing array index as the array length, so an add
at /5 on a two-element array appended the value. RFC 6902 section 4.1
requires an error unless the index equals the length or the token is "-".

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
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.

Value.Patch: "add" with an out-of-range array index appends instead of failing

1 participant