Skip to content

hujson: reject Patch add operations with an out-of-range array index - #53

Closed
RaphaelFakhri wants to merge 1 commit into
tailscale:masterfrom
RaphaelFakhri:fix/patch-add-array-index
Closed

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

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Description

Value.Patch silently appended the value for an add operation whose array index was greater than the array length. RFC 6902, section 4.1 requires an error in that case.

patchAdd now returns an error when the index is neither - nor exactly the array length. Indexes of existing elements and the append cases are unchanged.

Testing

Three cases are added to TestPatch: index equal to the length appends, - appends, and index 5 on a two-element array returns an error and leaves the array unchanged.

go test -run TestPatch .

Before the change, one subtest fails. After the change, all 60 subtests pass.

Fixes #52

RFC 6902, section 4.1 requires the index of an "add" operation on an
array to be no greater than the array length. Patch instead silently
appended the value for any larger index. Return an error instead.

Fixes #52

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.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