File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ const tildes = /~/g;
8
8
const escapedSlash = / ~ 1 / g;
9
9
const escapedTilde = / ~ 0 / g;
10
10
11
+ const safeDecodeURIComponent = ( encodedURIComponent : string ) : string => {
12
+ try {
13
+ return decodeURIComponent ( encodedURIComponent ) ;
14
+ } catch {
15
+ return encodedURIComponent ;
16
+ }
17
+ } ;
18
+
11
19
/**
12
20
* This class represents a single JSON pointer and its resolved value.
13
21
*
@@ -181,7 +189,7 @@ class Pointer {
181
189
182
190
// Decode each part, according to RFC 6901
183
191
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 , "~" ) ) ;
185
193
}
186
194
187
195
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