Skip to content

Bug Report With Fix: Didn't support JSON Patch add to array end using path segment '/-' #434

Description

@WAcry

The JSON Patch (RFC 6902) spec allows using a path segment of '-' with the add operation to append to the end of an array. The current jsondiffpatch RFC6902 apply implementation did not support '/-' and treated it as 0.

Problems observed:

add with path '/array/-' failed to append to arrays.
'-' usage in non-add operations was not validated.

Proposed fix:

Implement support for add when the final path segment is '-' to append to the array end.
Validate and reject '-' for non-add operations (remove/replace/move/copy/test), per RFC 6902.

#433

Acceptance criteria:

add with '/-': appends to the target array’s end.
remove/replace/move/copy/test with '/-': throws clear error.
Unit tests cover both behaviors.

References:

https://datatracker.ietf.org/doc/html/rfc6902#section-4.1
https://datatracker.ietf.org/doc/html/rfc6902#appendix-A.16

If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions