Closed
Description
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:
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
Labels
No labels