From 7478f3e852a8a5ae6acb9672e2d1f8fb413b8e82 Mon Sep 17 00:00:00 2001 From: abhi-0203 Date: Sat, 19 Sep 2026 03:22:12 +0000 Subject: [PATCH 1/3] fix: validate assignment target in JsonPointer.set() Raise JsonPointerException instead of TypeError/IndexError when the assignment target does not support item assignment. - str is a Sequence so it bypasses the '-' check but raises TypeError on item assignment; catch with explicit isinstance(str) guard. - Out-of-range list indices raise IndexError; wrap in try/except. Fixes: #77 Closes: #77 --- jsonpointer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsonpointer.py b/jsonpointer.py index 2285ffc..1d3ce5a 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -211,8 +211,13 @@ def set(self, doc, value, inplace=True): if isinstance(parent, Sequence) and part == '-': parent.append(value) + elif isinstance(parent, str): + raise JsonPointerException("Cannot set value in a string") else: - parent[part] = value + try: + parent[part] = value + except (TypeError, IndexError) as e: + raise JsonPointerException("Invalid assignment target: %s" % (e,)) return doc From c7e5a97c001cad76726f2665debaee208d54c5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Thu, 1 Oct 2026 12:10:49 +0200 Subject: [PATCH 2/3] Fix string detection in JsonPointer.set() Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- jsonpointer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jsonpointer.py b/jsonpointer.py index 1d3ce5a..5dca612 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -209,10 +209,10 @@ def set(self, doc, value, inplace=True): (parent, part) = self.to_last(doc) - if isinstance(parent, Sequence) and part == '-': - parent.append(value) - elif isinstance(parent, str): +if isinstance(parent, str): raise JsonPointerException("Cannot set value in a string") + elif isinstance(parent, Sequence) and part == '-': + parent.append(value) else: try: parent[part] = value From a6adb1fd96df854e525ecb2073f74251ca08286d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Fri, 2 Oct 2026 13:05:43 +0200 Subject: [PATCH 3/3] Potential fix for pull request finding 'Fix dedentation causing IndentationError in JsonPointer.set()' Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- jsonpointer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsonpointer.py b/jsonpointer.py index 5dca612..e27a9ba 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -209,7 +209,7 @@ def set(self, doc, value, inplace=True): (parent, part) = self.to_last(doc) -if isinstance(parent, str): + if isinstance(parent, str): raise JsonPointerException("Cannot set value in a string") elif isinstance(parent, Sequence) and part == '-': parent.append(value)