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.