Skip to content

Commit

Permalink
Handle 'about:*' URLs in the CRC formatter
Browse files Browse the repository at this point in the history
Add about:blank resource to CRC formatter test
  • Loading branch information
brendankenny committed Jun 29, 2016
1 parent f5c9183 commit 6c18ebd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lighthouse-core/formatters/critical-request-chains.js
Expand Up @@ -208,11 +208,13 @@ class CriticalRequestChains extends Formatter {
const MAX_FILENAME_LENGTH = 64;
const parsedResourceURL = url.parse(resourceURL);
const hostname = parsedResourceURL.hostname;
let file = parsedResourceURL.path
// Remove any query strings.
.replace(/\?.*/, '')
// Grab the last two parts of the path.
// Handle 'about:*' URLs specially since they have no path.
let file = parsedResourceURL.protocol === 'about:' ? parsedResourceURL.href :
// Otherwise, remove any query strings from the path.
parsedResourceURL.path.replace(/\?.*/, '')
// And grab the last two parts.
.split('/').slice(-2).join('/');

if (file.length > MAX_FILENAME_LENGTH) {
file = file.slice(0, MAX_FILENAME_LENGTH) + '...';
}
Expand Down
13 changes: 12 additions & 1 deletion lighthouse-core/test/formatter/critical-request-chains.js
Expand Up @@ -50,12 +50,22 @@ const extendedInfo = {
transferSize: 1
},
children: {}
},
3: {
request: {
endTime: 18,
responseReceivedTime: 16,
startTime: 13,
url: 'about:blank',
transferSize: 1
},
children: {}
}
}
}
};

/* global describe, it */
/* eslint-env mocha */

describe('CRC Formatter', () => {
it('copes with invalid input', () => {
Expand All @@ -74,6 +84,7 @@ describe('CRC Formatter', () => {
assert.ok(/┗━┳ \/ \(example.com\)/im.test(output));
assert.ok(/┣━━ \/b.js \(example.com\) - 5000.00ms/im.test(output));
assert.ok(truncatedURLRegExp.test(output));
assert.ok(/about:blank/.test(output));
});

it('generates valid HTML output', () => {
Expand Down

0 comments on commit 6c18ebd

Please sign in to comment.