File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ export type FetchJsonResponse = {
82
82
83
83
type Header = { key : string , value : string } ;
84
84
85
+ function unpercent ( value : string ) : Uint8Array {
86
+ return toUtf8Bytes ( value . replace ( / % ( [ 0 - 9 a - f ] [ 0 - 9 a - f ] ) / gi, ( all , code ) => {
87
+ return String . fromCharCode ( parseInt ( code , 16 ) ) ;
88
+ } ) ) ;
89
+ }
90
+
85
91
// This API is still a work in progress; the future changes will likely be:
86
92
// - ConnectionInfo => FetchDataRequest<T = any>
87
93
// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }
@@ -165,15 +171,15 @@ export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo,
165
171
}
166
172
}
167
173
168
- const reData = new RegExp ( "^data:([a-z0-9-]+/[a-z0-9-]+) ;base64,(.*)$" , "i" ) ;
174
+ const reData = new RegExp ( "^data:([^;:]*)?( ;base64)? ,(.*)$" , "i" ) ;
169
175
const dataMatch = ( ( url ) ? url . match ( reData ) : null ) ;
170
176
if ( dataMatch ) {
171
177
try {
172
178
const response = {
173
179
statusCode : 200 ,
174
180
statusMessage : "OK" ,
175
- headers : { "content-type" : dataMatch [ 1 ] } ,
176
- body : base64Decode ( dataMatch [ 2 ] )
181
+ headers : { "content-type" : ( dataMatch [ 1 ] || "text/plain" ) } ,
182
+ body : ( dataMatch [ 2 ] ? base64Decode ( dataMatch [ 3 ] ) : unpercent ( dataMatch [ 3 ] ) )
177
183
} ;
178
184
179
185
let result : T = < T > < unknown > response . body ;
You can’t perform that action at this time.
0 commit comments