From 4aed89ca8944605d47d337d2a28c05b29664e134 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 21:13:56 +0000 Subject: [PATCH 1/3] Initial plan for issue From 4fb793ef0a73bd3117de2e38380e39f30be9188b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 May 2025 21:20:38 +0000 Subject: [PATCH 2/3] Fix array index validation to reject indices with leading zeros Co-authored-by: stefankoegl <184196+stefankoegl@users.noreply.github.com> --- jsonpointer.py | 2 +- tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jsonpointer.py b/jsonpointer.py index 3e97add..41d580c 100644 --- a/jsonpointer.py +++ b/jsonpointer.py @@ -152,7 +152,7 @@ class JsonPointer(object): # Array indices must not contain: # leading zeros, signs, spaces, decimals, etc - _RE_ARRAY_INDEX = re.compile('0|[1-9][0-9]*$') + _RE_ARRAY_INDEX = re.compile('^(?:0|[1-9][0-9]*)$') _RE_INVALID_ESCAPE = re.compile('(~[^01]|~$)') def __init__(self, pointer): diff --git a/tests.py b/tests.py index 7b1cdac..369f00c 100755 --- a/tests.py +++ b/tests.py @@ -219,6 +219,13 @@ def test_invalid_index(self): # 'a' is not a valid list index doc = [0, 1, 2] self.assertRaises(JsonPointerException, resolve_pointer, doc, '/a') + + def test_invalid_index_leading_zeros(self): + # RFC 6901 specifies that array indices must not have leading zeros + doc = [0, 1, 2] + self.assertRaises(JsonPointerException, resolve_pointer, doc, '/01') + self.assertRaises(JsonPointerException, resolve_pointer, doc, '/00') + self.assertRaises(JsonPointerException, resolve_pointer, doc, '/001') def test_oob(self): # this list does not have 10 members From c7b44162c1183e1b37ae29b79129a4e4c18a44bb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 09:18:04 +0000 Subject: [PATCH 3/3] Fix whitespace issue reported by flake8 Co-authored-by: stefankoegl <184196+stefankoegl@users.noreply.github.com> --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 369f00c..b4251fe 100755 --- a/tests.py +++ b/tests.py @@ -219,7 +219,7 @@ def test_invalid_index(self): # 'a' is not a valid list index doc = [0, 1, 2] self.assertRaises(JsonPointerException, resolve_pointer, doc, '/a') - + def test_invalid_index_leading_zeros(self): # RFC 6901 specifies that array indices must not have leading zeros doc = [0, 1, 2]