File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -279,7 +279,14 @@ export class EditorApp {
279
279
}
280
280
281
281
export const verifyUrlOrCreateDataUrl = ( input : string | URL ) => {
282
- return ( input instanceof URL ) ? input . href : new URL ( `data:text/plain;base64,${ btoa ( input ) } ` ) . href ;
282
+ if ( input instanceof URL ) {
283
+ return input . href ;
284
+ } else {
285
+ const bytes = new TextEncoder ( ) . encode ( input ) ;
286
+ const binString = Array . from ( bytes , ( b ) => String . fromCodePoint ( b ) ) . join ( '' ) ;
287
+ const base64 = btoa ( binString ) ;
288
+ return new URL ( `data:text/plain;base64,${ base64 } ` ) . href ;
289
+ }
283
290
} ;
284
291
285
292
export const didModelContentChange = ( textModels : TextModels , onTextChanged ?: ( textChanges : TextContents ) => void ) => {
Original file line number Diff line number Diff line change @@ -22,7 +22,18 @@ describe('Test EditorApp', () => {
22
22
test ( 'verifyUrlorCreateDataUrl: url' , async ( ) => {
23
23
const url = new URL ( '../../../node_modules/langium-statemachine-dsl/syntaxes/statemachine.tmLanguage.json' , window . location . href ) ;
24
24
const text = await ( await fetch ( url ) ) . text ( ) ;
25
- expect ( verifyUrlOrCreateDataUrl ( text ) ) . toBe ( `data:text/plain;base64,${ btoa ( text ) } ` ) ;
25
+ const bytes = new TextEncoder ( ) . encode ( text ) ;
26
+ const binString = Array . from ( bytes , ( b ) => String . fromCodePoint ( b ) ) . join ( '' ) ;
27
+ const base64 = btoa ( binString ) ;
28
+ expect ( verifyUrlOrCreateDataUrl ( text ) ) . toBe ( `data:text/plain;base64,${ base64 } ` ) ;
29
+ } ) ;
30
+
31
+ test ( 'verifyUrlorCreateDataUrl: url' , ( ) => {
32
+ const text = '✓✓' ;
33
+ const bytes = new TextEncoder ( ) . encode ( text ) ;
34
+ const binString = Array . from ( bytes , ( b ) => String . fromCodePoint ( b ) ) . join ( '' ) ;
35
+ const base64 = btoa ( binString ) ;
36
+ expect ( verifyUrlOrCreateDataUrl ( text ) ) . toBe ( `data:text/plain;base64,${ base64 } ` ) ;
26
37
} ) ;
27
38
28
39
test ( 'config defaults' , ( ) => {
You can’t perform that action at this time.
0 commit comments