@@ -266,6 +266,23 @@ export type UrlParametersType = {
266
266
ghfolder : string
267
267
}
268
268
269
+ /**
270
+ * Decode a base64‑encoded string that was produced by
271
+ * percent‑escaping UTF‑8 bytes and then encoded with btoa().
272
+ *
273
+ * @param {string } b64Payload The base64 payload you got from params.code
274
+ * @returns {string } The original UTF‑8 string
275
+ */
276
+ export const decodePercentEscapedBase64 = ( b64Payload : string ) => {
277
+ const rawByteString = atob ( b64Payload ) ;
278
+
279
+ const percentEscapedString = rawByteString . split ( '' )
280
+ . map ( c => '%' + c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , '0' ) )
281
+ . join ( '' )
282
+
283
+ return decodeURIComponent ( percentEscapedString ) ;
284
+ }
285
+
269
286
export const loadWorkspacePreset = async ( template : WorkspaceTemplate = 'remixDefault' , opts ?) => {
270
287
const workspaceProvider = plugin . fileProviders . workspace
271
288
const electronProvider = plugin . fileProviders . electron
@@ -283,7 +300,7 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
283
300
const hashed = bytesToHex ( hash . keccakFromString ( params . code ) )
284
301
285
302
path = 'contract-' + hashed . replace ( '0x' , '' ) . substring ( 0 , 10 ) + ( params . language && params . language . toLowerCase ( ) === 'yul' ? '.yul' : '.sol' )
286
- content = atob ( decodeURIComponent ( params . code ) )
303
+ content = decodePercentEscapedBase64 ( params . code )
287
304
await workspaceProvider . set ( path , content )
288
305
}
289
306
if ( params . shareCode ) {
@@ -586,7 +603,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
586
603
// the files module. Please ask the user here if they want to overwrite
587
604
// a file and then just use `files.add`. The file explorer will
588
605
// pick that up via the 'fileAdded' event from the files module.
589
- ; [ ...target . files ] . forEach ( async ( file ) => {
606
+ [ ...target . files ] . forEach ( async ( file ) => {
590
607
const workspaceProvider = plugin . fileProviders . workspace
591
608
const name = targetFolder === '/' ? file . name : `${ targetFolder } /${ file . name } `
592
609
0 commit comments