Skip to content

Commit 8c0bfdd

Browse files
authored
Merge pull request #80 from abhi-0203/fix/set-validate-assignment-target
fix: validate assignment target in JsonPointer.set()
2 parents 09b3cd7 + a6adb1f commit 8c0bfdd

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎jsonpointer.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,15 @@ def set(self, doc, value, inplace=True):
209209

210210
(parent, part) = self.to_last(doc)
211211

212-
if isinstance(parent, Sequence) and part == '-':
212+
if isinstance(parent, str):
213+
raise JsonPointerException("Cannot set value in a string")
214+
elif isinstance(parent, Sequence) and part == '-':
213215
parent.append(value)
214216
else:
215-
parent[part] = value
217+
try:
218+
parent[part] = value
219+
except (TypeError, IndexError) as e:
220+
raise JsonPointerException("Invalid assignment target: %s" % (e,))
216221

217222
return doc
218223

0 commit comments

Comments
 (0)