json-schema-org / json-schema-spec

The JSON Schema specification
http://json-schema.org/
Other
3.46k stars 251 forks source link

Relative JSON Pointer specification inconsistency #1175

Open omgmashina opened 2 years ago

omgmashina commented 2 years ago

First issue: text part of section 3. Syntax does not describe [index-manipulation] which is present in ABNF.

A Relative JSON Pointer is a Unicode string in UTF-8 encoding (see RFC 8259, Section 8 [RFC8259]), comprising a non-negative integer, followed by either a '#' (%x23) character or a JSON Pointer (RFC 6901 [RFC6901]).

relative-json-pointer =  non-negative-integer [index-manipulation] <json-pointer>
relative-json-pointer =/ non-negative-integer "#"
index-manipulation    =  ("+" / "-") non-negative-integer
non-negative-integer      =  %x30 / %x31-39 *( %x30-39 )
        ; "0", or digits without a leading "0"

Second issue: one of examples (0-1#) does not comply with ABNF -- # can't be used together with [index-manipulation].

                   For example, given the JSON document:

                         {
                            "foo": ["bar", "baz"],
                            "highly": {
                               "nested": {
                                  "objects": true
                               }
                            }
                         }

     Starting from the value "baz" (inside "foo"), the following JSON
               strings evaluate to the accompanying values:

                     "0"                         "baz"
                     "1/0"                       "bar"
                     "0-1"                       "bar"
                     "2/highly/nested/objects"   true
                     "0#"                        1
                     "0-1#"                      0
                     "1#"                        "foo"

Is ABNF the ultimate truth? Should I refer to it when implementing Relative JSON Pointers? Or does ABNF require fixes? In any case, I could make a pull request with fixes, if anyone can tell me what exactly needs to be fixed.

handrews commented 2 years ago

I can see this going either way. I believe the spec requires that the instance location to which # is applied must actually exist, which means that you can't just get the non-manipulated index and then add an adjustment to it. Or, rather, you would have to add the adjustment and then see if the resulting location exists, which is somewhat annoying. So I lean towards supporting 0-1#

@Relequestual I think this should be fixed in the patch release? If you agree with me here it's just that something was left out of the ABNF, so this would not be adding to the set of functionality expressed by the examples. Granted, the ABNF should be normative, but I think the intent was to support this.

handrews commented 2 years ago

Per Slack conversation with @Relequestual I believe that there will not be a release of the Relative JSON Pointer spec alongside the immanent JSON Schema patch release, but I am advocating for (and volunteering to do the work for) an update of Relative JSON Pointer shortly afterwards.

notEthan commented 5 months ago

It looks like this has been resolved by https://github.com/json-schema-org/json-schema-spec/pull/1400 and can be closed.

gregsdennis commented 5 months ago

Kind of. The spec still hasn't been republished. Henry tells me there's a bit more he wants to clarify/adjust on it, but he hasn't had time.