@@ -13,14 +13,6 @@ const tildes = /~/g;
1313const escapedSlash = / ~ 1 / g;
1414const escapedTilde = / ~ 0 / g;
1515
16- const safeDecodeURIComponent = ( encodedURIComponent : string ) : string => {
17- try {
18- return decodeURIComponent ( encodedURIComponent ) ;
19- } catch {
20- return encodedURIComponent ;
21- }
22- } ;
23-
2416/**
2517 * This class represents a single JSON pointer and its resolved value.
2618 *
@@ -124,7 +116,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
124116 // actually instead pointing to an existing `null` value then we should use that
125117 // `null` value.
126118 if ( token in this . value && this . value [ token ] === null ) {
127- // We use a `null` symbol for internal tracking to differntiate between a general `null`
119+ // We use a `null` symbol for internal tracking to differentiate between a general `null`
128120 // value and our expected `null` value.
129121 this . value = nullSymbol ;
130122 continue ;
@@ -226,7 +218,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
226218
227219 // Decode each part, according to RFC 6901
228220 for ( let i = 0 ; i < split . length ; i ++ ) {
229- split [ i ] = safeDecodeURIComponent ( split [ i ] . replace ( escapedSlash , "/" ) . replace ( escapedTilde , "~" ) ) ;
221+ split [ i ] = split [ i ] . replace ( escapedSlash , "/" ) . replace ( escapedTilde , "~" ) ;
230222 }
231223
232224 if ( split [ 0 ] !== "" ) {
@@ -254,7 +246,9 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
254246 for ( let i = 0 ; i < tokens . length ; i ++ ) {
255247 const token = tokens [ i ] ;
256248 // Encode the token, according to RFC 6901
257- base += "/" + encodeURIComponent ( token . replace ( tildes , "~0" ) . replace ( slashes , "~1" ) ) ;
249+ // RFC 6901 only requires encoding ~ as ~0 and / as ~1
250+ // We do NOT use encodeURIComponent as it encodes characters like $ which should remain literal
251+ base += "/" + token . replace ( tildes , "~0" ) . replace ( slashes , "~1" ) ;
258252 }
259253
260254 return base ;
0 commit comments