File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ export type FetchJsonResponse = {
8282
8383type Header = { key : string , value : string } ;
8484
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+
8591// This API is still a work in progress; the future changes will likely be:
8692// - ConnectionInfo => FetchDataRequest<T = any>
8793// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }
@@ -165,15 +171,15 @@ export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo,
165171 }
166172 }
167173
168- const reData = new RegExp ( "^data:([a-z0-9-]+/[a-z0-9-]+) ;base64,(.*)$" , "i" ) ;
174+ const reData = new RegExp ( "^data:([^;:]*)?( ;base64)? ,(.*)$" , "i" ) ;
169175 const dataMatch = ( ( url ) ? url . match ( reData ) : null ) ;
170176 if ( dataMatch ) {
171177 try {
172178 const response = {
173179 statusCode : 200 ,
174180 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 ] ) )
177183 } ;
178184
179185 let result : T = < T > < unknown > response . body ;
You can’t perform that action at this time.
0 commit comments