summaryrefslogtreecommitdiff
path: root/jsonpatch.py
diff options
context:
space:
mode:
authorVu-Hoang Phan <vu-hoang.phan@ubisoft.com>2021-04-06 13:33:18 +0200
committerVu-Hoang Phan <vu-hoang.phan@ubisoft.com>2021-04-06 13:52:39 +0200
commitdb194f820dee88e1a66a811a7a8653cce6965bc3 (patch)
tree8a5096edfbdf094f1496a7bb5ebdcf193954ac2c /jsonpatch.py
parenta6526489c4b741e1b603b5bb988ecc9aefd3e880 (diff)
downloadpython-json-patch-db194f820dee88e1a66a811a7a8653cce6965bc3.tar.gz
fix invalid remove index
Diffstat (limited to 'jsonpatch.py')
-rw-r--r--jsonpatch.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index 1bced46..238a6c9 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -39,6 +39,12 @@ import copy
import functools
import json
import sys
+
+try:
+ from collections.abc import Mapping, Sequence
+except ImportError: # Python 3
+ from collections import Mapping, Sequence
+
try:
from types import MappingProxyType
except ImportError:
@@ -234,6 +240,10 @@ class RemoveOperation(PatchOperation):
def apply(self, obj):
subobj, part = self.pointer.to_last(obj)
+
+ if isinstance(subobj, Sequence) and not isinstance(part, int):
+ raise JsonPointerException("invalid array index '{0}'".format(part))
+
try:
del subobj[part]
except (KeyError, IndexError) as ex: