Skip to content

Commit

Permalink
core(font-display): handle carriage returns (#7712)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed Mar 26, 2019
1 parent 9790337 commit 77d1656
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit 77d1656

Please sign in to comment.