Skip to content

fix: do not resolve array indexes that RFC 6901 does not allow - #20

Merged
jdesrosiers merged 2 commits into
hyperjump-io:v1from
filipesantoss:fix/invalid-array-index-v1
Nov 5, 2026
Merged

jdesrosiers merged 2 commits into
hyperjump-io:v1from
filipesantoss:fix/invalid-array-index-v1

Conversation

@filipesantoss

Copy link
Copy Markdown

Fixes #16

Summary

Reads and deletes look up the reference token as a JavaScript property lookup does.

Writes accept only an array index or - for an array.
Writes throw a TypeError with the cursor for any other token.

 get / unset / remove (token)
-  key = computeSegment(token)                    # parseInt for an array
-  if value has own property key
+  if value has own enumerable property token     # items, not an array's length
     read or delete it

 set / assign (token)
   computeSegment(value, token, location)
     if value is an array and token is "-"
       return value.length
-    return parseInt(token, 10)
+    if token is not "0" or digits without a leading "0"
+      throw TypeError "Value at '<cursor>' is an array and '<token>' is not a valid array index"
+    return Number(token)

Merge Danger

A token such as 01 no longer reaches item 1.
A caller that wrote through such a token now gets an error.
A write with a token that is not a number, such as foo, also throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Added one small change that makes writes throw for indexes above the largest supportable array index. I also added some test coverage.

@jdesrosiers
jdesrosiers merged commit 1c78c3b into hyperjump-io:v1 Nov 5, 2026
1 check passed
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.

2 participants