You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: JsonPointer.set() does not validate assignment target (RFC 6901 non-compliant) #77
JsonPointer.set() does not validate the assignment target, so it raises TypeError or IndexError instead of JsonPointerException. Mirror of #70
on the write path; PR #76 fixes resolve, set stays unguarded.
Reproduction
fromjsonpointerimportJsonPointerJsonPointer("/0").set("abc", {"v": 1}, inplace=False)
# TypeError: 'str' object does not support item assignmentJsonPointer("/0").set([], 42, inplace=False)
# IndexError: list assignment index out of rangeJsonPointer("/5").set([1, 2], 42, inplace=False)
# IndexError: list assignment index out of range
Root cause
ifisinstance(parent, Sequence) andpart=='-':
parent.append(value)
else:
parent[part] =value# str -> TypeError, list out of range -> IndexError
str is a Sequence, and there is no guard around the assignment.
Impact
jsonpatch catches IndexError but not TypeError, so JsonPatch.apply()
can raise TypeError on untrusted patch documents.
Activity