voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.54k stars 243 forks source link

JSON pointers are broken when they contain a `:` #319

Closed jayniz closed 8 years ago

jayniz commented 8 years ago

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.

jayniz commented 8 years ago

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

iainbeeston commented 8 years ago

@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 commented 8 years ago

Coolio, I tried your patch locally and it works great for me!

iainbeeston commented 8 years ago

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

jayniz commented 8 years ago

Thank you thank you thank you!