Skip to content

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

Open
filipesantoss wants to merge 1 commit into
hyperjump-io:v1from
filipesantoss:fix/invalid-array-index-v1
Open

filipesantoss wants to merge 1 commit 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.

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