hyperjump-io / json-pointer

An RFC-6901 JSON Pointer implementation
MIT License
4 stars 2 forks source link

Array element - (dash) syntax support #3

Closed MikeRalphson closed 4 years ago

MikeRalphson commented 4 years ago

I can't see any support or tests for the last paragraph of this section of RFC 6901:

o If the currently referenced value is a JSON array, the reference token MUST contain either:

  • characters comprised of digits (see ABNF below; note that leading zeros are not allowed) that represent an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index identified by the token, or
  • exactly the single character "-", making the new referenced value the (nonexistent) member after the last array element.

Should this be called out in the README as unsupported / always throwing an error?

I'm thinking specifically about this paragraph too:

For example, some applications might stop pointer processing upon an error, while others may attempt to recover from missing values by inserting default ones.

If you think supporting this is in scope, could you summarise your expectations for get, set and assign, and I could work up a PR?

jdesrosiers commented 4 years ago

That was an oversight, it should be supported.

No default values should be inserted. Attempting to access a - segment should result in the normal error Value at '${cursor}' does not have index '${segment}' except segment should be the computed index rather than -.

That means

Thanks for finding this and for working on a fix. I'm hopeful that this should just be a fairly small change to the applySegment function.

jdesrosiers commented 4 years ago

Published as v0.7.0