Skip to content

Commit 2223a85

Browse files
authored
Merge pull request #81 from LQBing/main
fix addap op as addne issue
2 parents 3b90209 + 9b83acb commit 2223a85

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

jsonpath/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class OpAddAp(OpAdd):
124124
"""A non-standard add operation that appends to arrays/lists .
125125
126126
This is like _OpAdd_, but assumes an index of "-" if the path can not
127-
be resolved.
127+
be resolved rather than raising a JSONPatchError.
128128
129129
**New in version 1.2.0**
130130
"""
@@ -419,7 +419,7 @@ def _build(self, patch: Iterable[Mapping[str, object]]) -> None:
419419
value=self._op_value(operation, "value", "addne", i),
420420
)
421421
elif op == "addap":
422-
self.addne(
422+
self.addap(
423423
path=self._op_pointer(operation, "path", "addap", i),
424424
value=self._op_value(operation, "value", "addap", i),
425425
)

tests/test_json_patch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,9 @@ def test_asdict() -> None:
262262

263263
patch = JSONPatch(patch_doc)
264264
assert patch.asdicts() == patch_doc
265+
266+
267+
def test_non_standard_addap_op() -> None:
268+
# Index 7 is out of range and would raises a JSONPatchError with the `add` op.
269+
patch = JSONPatch().addap(path="/foo/7", value=99)
270+
assert patch.apply({"foo": [1, 2, 3]}) == {"foo": [1, 2, 3, 99]}

0 commit comments

Comments
 (0)