Skip to content

Commit

Permalink
Merge pull request #15 from Wakamai-Fondue/fix/remove-null-bytes-in-o…
Browse files Browse the repository at this point in the history
…utput

Remove null bytes from output
  • Loading branch information
pascalw authored Sep 7, 2020
2 parents baeba18 + f05e25c commit e2e3e43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/fondue/Fondue.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ export default class Fondue {
NAME_RECORD[record.platformID].language[
record.languageID
];
const value = this.name(nameId);
const value = this._removeNullBytes(
this.name(nameId)
);
return {
id: nameId,
platformId,
Expand Down Expand Up @@ -376,13 +378,14 @@ export default class Fondue {

get customText() {
const text = this._font.opentype.tables.name.get(19);
if (text) {
// Currently Font.js returns null bytes in name table
// strings, we filter them here.
// https://github.com/Pomax/Font.js/issues/74
/* eslint-disable no-control-regex */
return text.replace(/\x00/g, "");
}
return null;
return text ? this._removeNullBytes(text) : null;
}

_removeNullBytes(value) {
// Currently Font.js returns null bytes in name table
// strings, we filter them here.
// https://github.com/Pomax/Font.js/issues/74
/* eslint-disable no-control-regex */
return value.replace(/\x00/g, "");
}
}
11 changes: 11 additions & 0 deletions test/Fondue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,14 @@ describe("nameTable", () => {
expect(fondue.customText).toContain("Wakamai Fondue rules!");
});
});

test("null bytes are omitted", async () => {
const fondue = await WFTestFont();

for (const prop in fondue.summary) {
const value = fondue.summary[prop];
const nullBytes = value.split("").filter((c) => c == "\u0000");

expect(nullBytes.length).toBe(0);
}
});

0 comments on commit e2e3e43

Please sign in to comment.