Skip to content

Commit

Permalink
fix: do not throw when checking URL equality (#1973)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Apr 7, 2017
1 parent 17046b3 commit 75d2768
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lighthouse-core/lib/url-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ function rewriteChromeInternalUrl(url) {
*/
URL.equalWithExcludedFragments = function(url1, url2) {
[url1, url2] = [url1, url2].map(rewriteChromeInternalUrl);
try {
url1 = new URL(url1);
url1.hash = '';

url1 = new URL(url1);
url1.hash = '';

url2 = new URL(url2);
url2.hash = '';
url2 = new URL(url2);
url2.hash = '';

return url1.href === url2.href;
return url1.href === url2.href;
} catch (e) {
return false;
}
};

module.exports = URL;
10 changes: 10 additions & 0 deletions lighthouse-core/test/lib/url-shim-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('URL Shim', () => {
assert.doesNotThrow(_ => new URL(url));
});

it.skip('handles URLs with multiple dashes', () => {
// from https://github.com/GoogleChrome/lighthouse/issues/1972
const url = 'https://r15---sn-o097znl7.googlevideo.com/generate_204?conn2';
assert.doesNotThrow(_ => new URL(url));
});

it('safely identifies valid URLs', () => {
assert.ok(URL.isValid('https://5321212.fls.net/page?query=string#hash'));
assert.ok(URL.isValid('https://localhost:8080/page?query=string#hash'));
Expand Down Expand Up @@ -177,5 +183,9 @@ describe('URL Shim', () => {
];
assert.ok(URL.equalWithExcludedFragments(...pair));
});

it('returns false for invalid URLs', () => {
assert.ok(!URL.equalWithExcludedFragments('utter nonsense', 'http://example.com'));
});
});
});

0 comments on commit 75d2768

Please sign in to comment.