Skip to content

fix(json): reject negative index in Decode.index - #176

Open
ranas-mukminov wants to merge 1 commit into
gren-lang:mainfrom
ranas-mukminov:fix/json-index-negative
Open

ranas-mukminov wants to merge 1 commit into
gren-lang:mainfrom
ranas-mukminov:fix/json-index-negative

Conversation

@ranas-mukminov

Copy link
Copy Markdown

Fixes #45.

Decode.index only checked index >= value.length, so a negative index fell through to value[index] (undefined). That produced a misleading error for most decoders, and returned Ok for decoders that succeed on any value (e.g. index -1 (succeed ()) on [1]).

This adds a guard before the existing bounds check that rejects negative indices with a proper expecting error, mirroring the existing longer-array message style. No other decoder behavior changes.

Note: the Gren test suite is in Gren and needs the Gren compiler, which is not available in this environment, so the change was verified with node --check on the edited kernel file only, plus manual review of the surrounding _Json_runHelp index case. Issues #46 (dict on null-prototype objects, already handled via Object.hasOwn) and #80 (Zone docs, no Browser.Env reference remains) were checked while researching this and appear already addressed in Gren, so they are not touched here.

@robinheghan

Copy link
Copy Markdown
Member

the Gren test suite is in Gren and needs the Gren compiler, which is not available in this environment,

There is a github action here that installs the gren compiler using devbox in order to run the tests.

I'd love if you wrote a test that triggers this error message.

The change itself looks good.

@robinheghan

Copy link
Copy Markdown
Member

Also, are you able to setup git commit signing?

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.

Decode.index doesn't check for negative numbers

2 participants