File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ const tildes = /~/g;
88const escapedSlash = / ~ 1 / g;
99const escapedTilde = / ~ 0 / g;
1010
11+ const safeDecodeURIComponent = ( encodedURIComponent : string ) : string => {
12+ try {
13+ return decodeURIComponent ( encodedURIComponent ) ;
14+ } catch {
15+ return encodedURIComponent ;
16+ }
17+ } ;
18+
1119/**
1220 * This class represents a single JSON pointer and its resolved value.
1321 *
@@ -181,7 +189,7 @@ class Pointer {
181189
182190 // Decode each part, according to RFC 6901
183191 for ( let i = 0 ; i < pointer . length ; i ++ ) {
184- pointer [ i ] = decodeURIComponent ( pointer [ i ] . replace ( escapedSlash , "/" ) . replace ( escapedTilde , "~" ) ) ;
192+ pointer [ i ] = safeDecodeURIComponent ( pointer [ i ] . replace ( escapedSlash , "/" ) . replace ( escapedTilde , "~" ) ) ;
185193 }
186194
187195 if ( pointer [ 0 ] !== "" ) {
Original file line number Diff line number Diff line change 1+ import { describe , it } from "vitest" ;
2+ import Pointer from "../../../lib/pointer" ;
3+
4+ describe ( "Pointers" , ( ) => {
5+ it ( "should parse successfully" , async ( ) => {
6+ Pointer . parse ( "#/c%d" ) ;
7+ } ) ;
8+ } ) ;
You can’t perform that action at this time.
0 commit comments