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

Don't crash in the reporting code when some pages don't make use of a font that's used on others #121

Merged
merged 1 commit into from
Jul 26, 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
4 changes: 1 addition & 3 deletions lib/subsetFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,7 @@ async function subsetFonts(
original: originalCodepoints,
used: usedCodepoints,
unused: unusedCodepoints,
page: fontUsage.pageText
? getCodepoints(fontUsage.pageText)
: undefined,
page: getCodepoints(fontUsage.pageText),
};
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/subfont.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,28 @@ describe('subfont', function () {
);
});
});

// Regression test for https://gitter.im/assetgraph/assetgraph?at=5f1ddc1afe6ecd2888764496
it('should not crash in the reporting code when a font has no text on a given page', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'noFontUsageOnOnePage'
)}`
);

await subfont(
{
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
);
});
});

describe('when subsetPerPage is true', function () {
Expand Down
Binary file added testdata/noFontUsageOnOnePage/OpenSans.ttf
Binary file not shown.
21 changes: 21 additions & 0 deletions testdata/noFontUsageOnOnePage/first.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(OpenSans.ttf) format('truetype');
}

h1 {
font-family: 'Open Sans';
}
</style>
</head>
<body>
<h1>Foo</h1>
</body>
</html>
21 changes: 21 additions & 0 deletions testdata/noFontUsageOnOnePage/second.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans Regular'), local('OpenSans-Regular'), url(OpenSans.ttf) format('truetype');
}

h1 {
font-family: 'Open Sans';
}
</style>
</head>
<body>
<h1></h1>
</body>
</html>