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

core(font-display): handle carriage returns #7712

Merged
merged 1 commit into from
Mar 26, 2019
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
2 changes: 1 addition & 1 deletion lighthouse-core/audits/font-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FontDisplay extends Audit {
// Go through all the stylesheets to find all @font-face declarations
for (const stylesheet of artifacts.CSSUsage.stylesheets) {
// Eliminate newlines so we can more easily scan through with a regex
const newlinesStripped = stylesheet.content.replace(/\n/g, ' ');
const newlinesStripped = stylesheet.content.replace(/(\r|\n)+/g, ' ');
// Find the @font-faces
const fontFaceDeclarations = newlinesStripped.match(/@font-face\s*{(.*?)}/g) || [];
// Go through all the @font-face declarations to find a declared `font-display: ` property
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/test/audits/font-display-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ describe('Performance: Font Display audit', () => {
it('passes when all fonts have a correct font-display rule', async () => {
stylesheet.content = `
@font-face {
/* make sure we can handle carriage returns */
\r\n
font-display: block;
/* try with " */
src: url("./font-a.woff");
}

@font-face {
@font-face {\r
font-display: fallback;
/* try up a directory with ' */
src: url('../font-b.woff');
}

@font-face {
@font-face {\n
font-display: optional;
/* try no path with no quotes ' */
src: url(font.woff);
Expand Down