Skip to content

[BUGFIX] Forbid array references with leading zeros#69

Merged
stefankoegl merged 4 commits intostefankoegl:masterfrom
angela-tarantula:patch-1
Mar 23, 2026
Merged

[BUGFIX] Forbid array references with leading zeros#69
stefankoegl merged 4 commits intostefankoegl:masterfrom
angela-tarantula:patch-1

Conversation

@angela-tarantula
Copy link
Copy Markdown
Contributor

Fixes #63

Use re.fullmatch instead of re.match to forbid indices with leading zeros in order to be RFC6901-compliant.

Before:

>>> from jsonpointer import JsonPointer
>>> JsonPointer("/array/01").resolve({"array": [1,2,3]})
2

After:

>>> from jsonpointer import JsonPointer
>>> JsonPointer("/array/01").resolve({"array": [1,2,3]})
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    JsonPointer("/array/01").resolve({"array": [1,2,3]})
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/python-json-pointer/jsonpointer.py", line 190, in resolve
    doc = self.walk(doc, part)
  File "/python-json-pointer/jsonpointer.py", line 255, in walk
    part = JsonPointer.get_part(doc, part)
  File "/python-json-pointer/jsonpointer.py", line 234, in get_part
    raise JsonPointerException("'%s' is not a valid sequence index" % part)
jsonpointer.JsonPointerException: '01' is not a valid sequence index

@stefankoegl stefankoegl merged commit 0e9ea50 into stefankoegl:master Mar 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Invalid Array Index Validation in python-json-pointer

2 participants