diff --git a/src/fondue/Fondue.js b/src/fondue/Fondue.js index a855085..ed5c06c 100644 --- a/src/fondue/Fondue.js +++ b/src/fondue/Fondue.js @@ -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, @@ -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, ""); } } diff --git a/test/Fondue.test.js b/test/Fondue.test.js index e33428f..7091907 100644 --- a/test/Fondue.test.js +++ b/test/Fondue.test.js @@ -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); + } +});