Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove null bytes from output #15

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
});