From cfece3451d4240d8e7e6959a51b327c21ffe7c2a Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 29 Sep 2017 08:29:19 +0900 Subject: [PATCH] fix(Network): Do not attempt to normalize malformed URLs. (#875) This patch avoids throwing 'url malformed' error during generating request hash for request interception. Fixes #869. --- lib/NetworkManager.js | 11 +++++++++-- test/test.js | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index cabed3137b0..a37fe777a12 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -394,9 +394,16 @@ helper.tracePublicAPI(Response); * @return {string} */ function generateRequestHash(request) { - const hash = { + let normalizedURL = request.url; + try { // Decoding is necessary to normalize URLs. @see crbug.com/759388 - url: decodeURI(request.url), + // The method will throw if the URL is malformed. In this case, + // consider URL to be normalized as-is. + normalizedURL = decodeURI(request.url); + } catch (e) { + } + const hash = { + url: normalizedURL, method: request.method, postData: request.postData, headers: {}, diff --git a/test/test.js b/test/test.js index 3b9883596ce..a41f5bccc1a 100644 --- a/test/test.js +++ b/test/test.js @@ -979,6 +979,13 @@ describe('Page', function() { const response = await page.goto(PREFIX + '/some nonexisting page'); expect(response.status).toBe(404); })); + it('should work with badly encoded URLs', SX(async function() { + await page.setRequestInterceptionEnabled(true); + server.setRoute('/malformed?rnd=%911', (req, res) => res.end()); + page.on('request', request => request.continue()); + const response = await page.goto(PREFIX + '/malformed?rnd=%911'); + expect(response.status).toBe(200); + })); it('should work with encoded URLs - 2', SX(async function() { // The requestWillBeSent will report URL as-is, whereas interception will // report encoded URL for stylesheet. @see crbug.com/759388