Repository navigation
fix: do not resolve array indexes that RFC 6901 does not allow - #17
filipesantoss wants to merge 2 commits into
Conversation
jdesrosiers
left a comment
There was a problem hiding this comment.
The strict index check is right for writes, but it shouldn't apply to reads. Here's what I'd like and why.
This library tries to behave the way JavaScript does for the same operation, unless that would contradict RFC 6901.
Reads and deletes should not throw. In JavaScript, [1, 2]["01"] and [1]["foo"] are just property lookups that give undefined. So get should return undefined, and unset/remove should do nothing. This doesn't contradict the spec. Section 7 lists a reference to a nonexistent value as an error, but it leaves the handling of errors to the application, and this library already handles that case by returning undefined.
Writes should throw. In JavaScript, arr["01"] = x adds a non-index property to the array. That gives you a value that isn't valid JSON: JSON.stringify drops the property without any warning. Section 4 also says that when the value is an array, the token MUST be - or an index with no leading zeros. So set and assign are where the check belongs.
The error should follow the existing ones. Please make it a TypeError that includes the location, like the not-a-container errors. For example: Value at '/0' is an array and 'foo' is not a valid array index.
|
8577327 addresses the review. Own enumerable propertiesWith NaNWith |
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
TypeErrorwith the cursor for any other token.Merge Danger
A token such as
01no 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.