Browse Source

Fixed JavaScript modules with special characters not displayed correctly in the editor

pull/15498/head
Maksym Tsymbarov 5 months ago
parent
commit
c7e8262933
  1. 8
      ui-ngx/src/app/core/utils.ts
  2. 2
      ui-ngx/src/app/shared/components/file-input.component.ts

8
ui-ngx/src/app/core/utils.ts

@ -210,7 +210,13 @@ export function objToBase64(obj: any): string {
}
export function base64toString(b64Encoded: string): string {
return decodeURIComponent(atob(b64Encoded).split('').map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''));
const binary = atob(b64Encoded);
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
try {
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
} catch {
return new TextDecoder('iso-8859-1').decode(bytes);
}
}
export function objToBase64URI(obj: any): string {

2
ui-ngx/src/app/shared/components/file-input.component.ts

@ -235,7 +235,7 @@ export class FileInputComponent extends PageComponent implements AfterViewInit,
if (this.readAsBinary) {
reader.readAsBinaryString(file.file);
} else {
reader.readAsText(file.file);
reader.readAsText(file.file, 'ISO-8859-1');
}
});
}

Loading…
Cancel
Save