Skip to content

Commit 0e9ea50

Browse files
authored
Merge pull request #69 from angela-tarantula/patch-1
[BUGFIX] Forbid array references with leading zeros
2 parents 97cd230 + 928959c commit 0e9ea50

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

jsonpointer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def get_part(cls, doc, part):
228228
if part == '-':
229229
return part
230230

231-
if not JsonPointer._RE_ARRAY_INDEX.match(str(part)):
231+
if not JsonPointer._RE_ARRAY_INDEX.fullmatch(str(part)):
232232
raise JsonPointerException("'%s' is not a valid sequence index" % part)
233233

234234
return int(part)

tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def test_trailing_escape(self):
215215
def test_invalid_escape(self):
216216
self.assertRaises(JsonPointerException, JsonPointer, '/foo/bar~2')
217217

218+
def test_leading_zero(self):
219+
doc = [0, 1, 2]
220+
self.assertRaises(JsonPointerException, resolve_pointer, doc, '/01')
221+
218222

219223
class ToLastTests(unittest.TestCase):
220224

0 commit comments

Comments
 (0)