From 0cb92090730afbf00e4a3bb50d2db1a0e8f09620 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 9 Feb 2017 17:26:51 -0800 Subject: [PATCH] fix: table formatter image preview URL encode (#1678) --- lighthouse-core/formatters/table.js | 4 +++- lighthouse-core/test/formatter/table-formatter-test.js | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/formatters/table.js b/lighthouse-core/formatters/table.js index 1fd9855e8c8e..d606df62db61 100644 --- a/lighthouse-core/formatters/table.js +++ b/lighthouse-core/formatters/table.js @@ -94,7 +94,9 @@ class Table extends Formatter { switch (key) { case 'preview': if (/^image/.test(value.mimeType)) { - return `[![Image preview](${value.url} "Image preview")](${value.url})`; + // Markdown can't handle URLs with parentheses which aren't automatically encoded + const encodedUrl = value.url.replace(/\)/g, '%29'); + return `[![Image preview](${encodedUrl} "Image preview")](${encodedUrl})`; } return ''; case 'code': diff --git a/lighthouse-core/test/formatter/table-formatter-test.js b/lighthouse-core/test/formatter/table-formatter-test.js index 0adda23218de..63fcd35439cc 100644 --- a/lighthouse-core/test/formatter/table-formatter-test.js +++ b/lighthouse-core/test/formatter/table-formatter-test.js @@ -34,7 +34,7 @@ describe('TableFormatter', () => { code: 'code snippet', isEval: true, pre: 'pre snippet', - preview: {url: 'http://example.com/i.jpg', mimeType: 'image/jpeg'} + preview: {url: 'http://example.com/(format:webp)/i.jpg', mimeType: 'image/jpeg'} }] }; @@ -57,8 +57,9 @@ describe('TableFormatter', () => { assert.equal(table.rows[0].cols[2], '\`code snippet\`'); assert.equal(table.rows[0].cols[3], 'yes'); assert.equal(table.rows[0].cols[4], '\`\`\`\npre snippet\`\`\`'); + const expectedUrl = 'http://example.com/(format:webp%29/i.jpg'; assert.equal(table.rows[0].cols[5], - '[![Image preview](http://example.com/i.jpg "Image preview")](http://example.com/i.jpg)'); + `[![Image preview](${expectedUrl} "Image preview")](${expectedUrl})`); }); it('generates valid pretty output', () => {