From c4a2c406cc17bfb25d8d2d823abb6f4a8e86e8a9 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 8 Nov 2019 09:14:49 -0600 Subject: [PATCH] fix(utils): more aggressive non-deterministic replacements --- packages/utils/src/audit-diff-finder.js | 16 ++++++++++++---- packages/utils/test/audit-diff-finder.test.js | 12 +++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/utils/src/audit-diff-finder.js b/packages/utils/src/audit-diff-finder.js index 7449111f3..cde1e3a9d 100644 --- a/packages/utils/src/audit-diff-finder.js +++ b/packages/utils/src/audit-diff-finder.js @@ -321,10 +321,18 @@ function synthesizeItemKeyDiffs(diffs, baseItems, compareItems) { /** @param {string} s */ function replaceNondeterministicStrings(s) { - return s - .replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, 'UUID') - .replace(/:[0-9]{3,5}\//, ':PORT/') - .replace(/\.[0-9a-f]{8}\.(js|css|woff|html|png|jpeg|jpg|svg)/, '.HASH.$1'); + return ( + s + // YouTube Embeds + .replace(/www-embed-player-[0-9a-z]+/i, 'www-embed-player') + .replace(/player_ias-[0-9a-z]+/i, 'player_ias') + // UUIDs + .replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, 'UUID') + // localhost Ports + .replace(/:[0-9]{3,5}\//, ':PORT/') + // Hash components embedded in filenames + .replace(/(\.|-)[0-9a-f]{8}\.(js|css|woff|html|png|jpeg|jpg|svg)/i, '$1HASH.$2') + ); } /** @param {Record} item @return {string} */ diff --git a/packages/utils/test/audit-diff-finder.test.js b/packages/utils/test/audit-diff-finder.test.js index 66a5e4c2f..e2c95f1b6 100644 --- a/packages/utils/test/audit-diff-finder.test.js +++ b/packages/utils/test/audit-diff-finder.test.js @@ -891,9 +891,19 @@ describe('#replaceNondeterministicStrings', () => { ); }); + it('should replace YouTube embeds', () => { + expect( + replaceNondeterministicStrings('/yts/jsbin/www-embed-player-vfl7uF46t/www-embed-player.js') + ).toEqual('/yts/jsbin/www-embed-player/www-embed-player.js'); + expect(replaceNondeterministicStrings('/yts/jsbin/player_ias-vflyrg3IP/en_US/base.js')).toEqual( + '/yts/jsbin/player_ias/en_US/base.js' + ); + }); + it('should replace hash parts', () => { expect(replaceNondeterministicStrings('foo.12345678.js')).toEqual('foo.HASH.js'); - expect(replaceNondeterministicStrings('foo.abcdef12.js')).toEqual('foo.HASH.js'); + expect(replaceNondeterministicStrings('foo.abcdef12.woff2')).toEqual('foo.HASH.woff2'); + expect(replaceNondeterministicStrings('foo-abcdef12.css')).toEqual('foo-HASH.css'); }); it('should replace ports', () => {