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
The current regex pattern used to validate array indices in the jsonpointer package incorrectly accepts indices with leading zeros, which violates JSON Pointer specification (RFC 6901).
Current Implementation:
_RE_ARRAY_INDEX=re.compile('0|[1-9][0-9]*$')
Issue
The current regex pattern has a logical flaw where it accepts invalid array indices with leading zeros (e.g., "01", "02", "0123"). This happens because:
The pattern 0|[1-9][0-9]*$ is an OR condition
The first part 0 is not properly anchored
Any string starting with "0" will match the first part of the OR condition, regardless of what follows
Test Case
pattern=re.compile('0|[1-9][0-9]*$')
assertpattern.match('01') # This incorrectly returns a matchassertpattern.match('0123') # This incorrectly returns a match
Expected Behavior
According to RFC 6901:
Array indices must not have leading zeros
Valid indices: "0", "1", "2", "10", "20", etc.
Invalid indices: "01", "02", "00", "01234", etc.
Proposed Fix
The regex pattern should be updated to:
_RE_ARRAY_INDEX=re.compile('^(?:0|[1-9][0-9]*)$')
This fix:
Anchors the pattern to the start of string with ^
Uses a non-capturing group (?:...) for efficiency
Properly validates that the entire string must match either:
A single "0", or
A number starting with 1-9 followed by zero or more digits
Impact
This bug could potentially lead to inconsistent behavior when working with JSON documents, especially in systems that rely on strict JSON Pointer compliance.
The text was updated successfully, but these errors were encountered:
Description
The current regex pattern used to validate array indices in the
jsonpointer
package incorrectly accepts indices with leading zeros, which violates JSON Pointer specification (RFC 6901).Current Implementation:
Issue
The current regex pattern has a logical flaw where it accepts invalid array indices with leading zeros (e.g., "01", "02", "0123"). This happens because:
0|[1-9][0-9]*$
is an OR condition0
is not properly anchoredTest Case
Expected Behavior
According to RFC 6901:
Proposed Fix
The regex pattern should be updated to:
This fix:
^
(?:...)
for efficiencyImpact
This bug could potentially lead to inconsistent behavior when working with JSON documents, especially in systems that rely on strict JSON Pointer compliance.
The text was updated successfully, but these errors were encountered: