Skip to content

Commit

Permalink
fix(developer): use TextDecoder to convert Uint8Array to string
Browse files Browse the repository at this point in the history
`toString()` only works when the Uint8Array is actually a Node Buffer.
  • Loading branch information
mcdurdin committed Oct 11, 2024
1 parent 43e7d32 commit 7dc787b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class KPJFileReader {
let data: KPJFile;

data = new KeymanXMLReader('kpj')
.parse(file.toString());
.parse(new TextDecoder().decode(file));

data = this.boxArrays(data);
if(data.KeymanDeveloperProject?.Files?.File?.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class KVKSFileReader {

try {
source = new KeymanXMLReader('kvks')
.parse(file.toString()) as KVKSourceFile;
.parse(new TextDecoder().decode(file)) as KVKSourceFile;
} catch(e) {
if(file.byteLength > 4 && file.subarray(0,3).every((v,i) => v == KVK_HEADER_IDENTIFIER_BYTES[i])) {
throw new Error('File appears to be a binary .kvk file', {cause: e});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class LDMLKeyboardXMLSourceFileReader {

loadTestDataUnboxed(file: Uint8Array): any {
const source = new KeymanXMLReader('keyboardTest3')
.parse(file.toString()) as any;
.parse(new TextDecoder().decode(file)) as any;
return source;
}

Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-package/src/compiler/kmp-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class KmpCompiler implements KeymanCompiler {

try {
a = new KeymanXMLReader('kps')
.parse(data.toString()) as KpsFile.KpsPackage;
.parse(data) as KpsFile.KpsPackage;
} catch(e) {
this.callbacks.reportMessage(PackageCompilerMessages.Error_InvalidPackageFile({e}));
}
Expand Down

0 comments on commit 7dc787b

Please sign in to comment.