Skip to content

Handle negative array indices without panicking - #98

Open
ac1982 wants to merge 1 commit into
bitly:masterfrom
ac1982:fix/negative-array-index
Open

ac1982 wants to merge 1 commit into
bitly:masterfrom
ac1982:fix/negative-array-index

Conversation

@ac1982

@ac1982 ac1982 commented Oct 10, 2026

Copy link
Copy Markdown

GetIndex(-1) panics on an array, including an empty array, while an out-of-range positive index returns a chainable null Json value.

Check the lower bound as well as the upper bound before indexing the slice. Tests cover -1, the minimum/maximum int, an out-of-range positive index, empty/populated arrays, null/object values, valid endpoints, and chaining through a missing index.

The regression panics on the original base. go test -race ./..., go vet ./..., gofmt and git diff --check pass (Go 1.27.1, Linux arm64).

All-state issue/PR searches for GetIndex, negative and index found no matching fix. #22 concerns Must* variadic defaults, #41 a nil receiver, and open #96/#97 nested Json values/trailing input, all separate behaviors. No API or dependency change.

AI assistance: prepared and tested with Codex.

Signed-off-by: AC <ac@fabtek.cn>
@qodo-for-bitly

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Great, no issues found!

Qodo reviewed your code and found no material issues that require review
Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗


Powered by Qodo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant