Skip to content

JSON Pointer parsing #296

Closed
Closed
@char0n

Description

@char0n

Hi,

I've noticed that implementation of JSON Pointer parsing is not compliant with RFC 6901, nor it's safe (throws error). The issue is with decodeURIComponent, which trows error in certain character sequences which are valid JSON Pointers.

Steps to Reproduce

const Pointer = require('@apidevtools/json-schema-ref-parser/lib/pointer.js');

Pointer.parse('#/c%d');

/c%d - is valid JSON Pointer according to the RFC 6901 (section 5), which has a nice example suitable for creating a test suite for the implementation:

image

Remediation

Remediation might be introduced by safe variant of decodeURIComponent that will look as follows:

const safeDecodeURIComponent = (encodedURIComponent: string): string => {
  try {
    return decodeURIComponent(encodedURIComponent);
  } catch {
    return encodedURIComponent;
  }
};

This safe version at least gives us chance to evaluate the JSON Pointer against the structure, even though not all character sequences might get decoded.

Metadata

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