Skip to content

JSON pointers are broken when they contain a :  #319

Closed
@jayniz

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions