Skip to content

Commit 9b83acb

Browse files
committed
Add a test for JSON Patch op addap
1 parent 7c3bb0d commit 9b83acb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

jsonpath/patch.py

Lines changed: 1 addition & 1 deletion
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
"""

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)