diff --git a/jsonpath/patch.py b/jsonpath/patch.py index ce5c054..913987c 100644 --- a/jsonpath/patch.py +++ b/jsonpath/patch.py @@ -124,7 +124,7 @@ class OpAddAp(OpAdd): """A non-standard add operation that appends to arrays/lists . This is like _OpAdd_, but assumes an index of "-" if the path can not - be resolved. + be resolved rather than raising a JSONPatchError. **New in version 1.2.0** """ @@ -419,7 +419,7 @@ def _build(self, patch: Iterable[Mapping[str, object]]) -> None: value=self._op_value(operation, "value", "addne", i), ) elif op == "addap": - self.addne( + self.addap( path=self._op_pointer(operation, "path", "addap", i), value=self._op_value(operation, "value", "addap", i), ) diff --git a/tests/test_json_patch.py b/tests/test_json_patch.py index eec2db7..64fafaf 100644 --- a/tests/test_json_patch.py +++ b/tests/test_json_patch.py @@ -262,3 +262,9 @@ def test_asdict() -> None: patch = JSONPatch(patch_doc) assert patch.asdicts() == patch_doc + + +def test_non_standard_addap_op() -> None: + # Index 7 is out of range and would raises a JSONPatchError with the `add` op. + patch = JSONPatch().addap(path="/foo/7", value=99) + assert patch.apply({"foo": [1, 2, 3]}) == {"foo": [1, 2, 3, 99]}