Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON pointers: "/" and "~" are not escaped #121

Closed
olofheurgren opened this issue Dec 5, 2022 · 1 comment · Fixed by #122
Closed

JSON pointers: "/" and "~" are not escaped #121

olofheurgren opened this issue Dec 5, 2022 · 1 comment · Fixed by #122

Comments

@olofheurgren
Copy link

Hi!

The RFC for JSON Pointer states that:

Because the characters '~' (%x7E) and '/' (%x2F) have special meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/' needs to be encoded as '~1' when these characters appear in a reference token.

but it seems this is not done for the JSON pointers included in the return value of validate.

For instance, this code:

schemer = JSONSchemer.schema(
  {'type' => 'object',
   'properties' => {
     'foo/bar~' => {
       'type' => 'string'}}}
)
schemer.validate({'foo/bar~' => 1}).to_a

returns:

[{"data"=>1,
  "data_pointer"=>"/foo/bar~",
  "schema"=>{"type"=>"string"},
  "schema_pointer"=>"/properties/foo/bar~",
  "root_schema"=>{"type"=>"object", "properties"=>{"foo/bar~"=>{"type"=>"string"}}},
  "type"=>"string"}]

but according to the RFC, the value of "data_pointer" should be:

"/foo~1bar~0"

and the value of "schema_pointer" should be

"/properties/foo~1bar~0"
davishmcclurg added a commit that referenced this issue Dec 7, 2022
When building `data_pointer` and `schema_pointer` in error objects.

JSON Pointer RFC[0]:

> Because the characters '~' (%x7E) and '/' (%x2F) have special
> meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
> needs to be encoded as '~1' when these characters appear in a
> reference token.

Fixes: #121

[0]: https://www.rfc-editor.org/rfc/rfc6901#section-3
davishmcclurg added a commit that referenced this issue Dec 7, 2022
When building `data_pointer` and `schema_pointer` in error objects.

JSON Pointer [RFC][0]:

```
Because the characters '~' (%x7E) and '/' (%x2F) have special
meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
needs to be encoded as '~1' when these characters appear in a
reference token.
```

Fixes: #121

[0]: https://www.rfc-editor.org/rfc/rfc6901#section-3
davishmcclurg added a commit that referenced this issue Dec 7, 2022
When building `data_pointer` and `schema_pointer` in error objects.

[JSON Pointer RFC][0]:

```
Because the characters '~' (%x7E) and '/' (%x2F) have special
meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
needs to be encoded as '~1' when these characters appear in a
reference token.
```

Fixes: #121

[0]: https://www.rfc-editor.org/rfc/rfc6901#section-3
@davishmcclurg
Copy link
Owner

Thanks for opening the issue @olofheurgren! Good catch.

I opened a fix: #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants