voxpupuli/json-schema

JSON pointers are broken when they contain a `:`

Closed this issue · 5 comments

If I read RFC 6901 correctly (and I'm slightly RFC impaired), the colon character : should be OK to use in JSON pointers. However, json-schema-2.6.1 will break, check out this ready to run gist.

The RFC states:

 The ABNF syntax of a JSON Pointer is:

      json-pointer    = *( "/" reference-token )
      reference-token = *( unescaped / escaped )
      unescaped       = %x00-2E / %x30-7D / %x7F-10FFFF
         ; %x2F ('/') and %x7E ('~') are excluded from 'unescaped'
      escaped         = "~" ( "0" / "1" )
        ; representing '~' and '/', respectively

So a : in a JSON pointer should be OK whereas / and ~ must be escaped:

> !!":"[/[\u0000-\u002E\u0030-\u007d\u007F-\u10FFFF]/] # : is OK
=> true
> !!"~"[/[\u0000-\u002E\u0030-\u007d\u007F-\u10FFFF]/] # ~ must be escaped
=> false
> !!"/"[/[\u0000-\u002E\u0030-\u007d\u007F-\u10FFFF]/] # / must be escaped
=> false
>

If you run the gist, though, you'll see something like

~/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/json-schema-2.6.1/lib/json-schema/attributes/ref.rb:63:in `block in get_referenced_uri_and_schema': The fragment '/definitions/thing' does not exist on schema af6a3d4a-9191-5753-9d90-edb43a637c46 (JSON::Schema::SchemaError)

If you paste the schema and data examples from the gist into an online JSON Schema tool like http://jsonschemalint.com/draft4/ it works as expected.

@iainbeeston: I saw that you fixed this in b2e4fde in your fork, awesome! Is there anything I can do to help get it released?

@jayniz Sorry, I haven't had time to merge and release this yet, but I might get a chance tomorrow. I'll update this ticket once it's released

@jayniz I've just released v2.6.2, which has the fix