Skip to content

fix: validate array index syntax before evaluation - #12

Open
ac1982 wants to merge 1 commit into
qri-io:masterfrom
ac1982:fix-array-index-validation
Open

ac1982 wants to merge 1 commit into
qri-io:masterfrom
ac1982:fix-array-index-validation

Conversation

@ac1982

@ac1982 ac1982 commented Oct 11, 2026

Copy link
Copy Markdown

Array evaluation currently accepts signed and zero-padded indices (-0, +0, +1, 00, 01), and a negative index such as -1 panics when indexing the slice. These tokens do not satisfy the array-index grammar in RFC 6901 section 4.

Require the parsed index to be nonnegative and to round-trip to the same decimal token before indexing. This keeps overflow and out-of-bounds errors intact. The restriction applies only while evaluating arrays: object properties named -1, 01, etc. remain accessible.

Regression coverage includes negative/signed/zero-padded, empty, append-marker, fractional, and overflowing tokens, with matching object-key checks. Before the fix the negative case panics and five other cases return an array value instead of an error.

Validation: full Go 1.27.1 race/coverage suite, go vet, golint -set_exit_status, formatting/diff checks, and full Go 1.9.7 tests pass. Go 1.14.15 also passes. Tests ran on Linux/arm64.

AI assistance: implementation and tests were developed and verified with an AI coding agent.

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.

1 participant