diff --git a/app/backend/__tests__/network.test.js b/app/backend/__tests__/network.test.js index cd924f287..6cde22b8d 100644 --- a/app/backend/__tests__/network.test.js +++ b/app/backend/__tests__/network.test.js @@ -17,6 +17,7 @@ describe('buildRequestConfig()', () => { expect(config).toEqual({ body: '', followAllRedirects: true, + forever: true, gzip: true, headers: {host: ''}, maxRedirects: 20, @@ -37,7 +38,7 @@ describe('buildRequestConfig()', () => { parameters: [{name: 'foo bar', value: 'hello&world'}], method: 'POST', body: 'foo=bar', - url: 'http://foo.com:3332/★/foo%20bar?bar=baz', + url: 'http://foo.com:3332/★/hi@gmail.com/foo%20bar?bar=baz', authentication: { username: 'user', password: 'pass' @@ -49,6 +50,7 @@ describe('buildRequestConfig()', () => { expect(config).toEqual({ body: 'foo=bar', followAllRedirects: true, + forever: true, gzip: true, headers: { 'Content-Type': 'application/json', @@ -61,7 +63,8 @@ describe('buildRequestConfig()', () => { rejectUnauthorized: true, time: true, timeout: 0, - url: 'http://foo.com:3332/%E2%98%85/foo%20bar?bar=baz&foo%20bar=hello%26world' + url: 'http://foo.com:3332/%E2%98%85/hi%40gmail.com/' + + 'foo%20bar?bar=baz&foo%20bar=hello%26world' }) }) }); diff --git a/app/backend/__tests__/util.test.js b/app/backend/__tests__/util.test.js index 485f11d20..565253e16 100644 --- a/app/backend/__tests__/util.test.js +++ b/app/backend/__tests__/util.test.js @@ -106,7 +106,7 @@ describe('prepareUrlForSending()', () => { it('encodes pathname mixed encoding', () => { const url = util.prepareUrlForSending('https://google.com/foo bar baz%20qux/100%/foo%25'); - expect(url).toBe('https://google.com/foo%20bar%20baz%20qux/100%25/foo%2525'); + expect(url).toBe('https://google.com/foo%20bar%20baz%20qux/100%25/foo%25'); }); it('leaves already encoded pathname', () => { diff --git a/app/backend/util.js b/app/backend/util.js index 74861239a..f49eaa813 100644 --- a/app/backend/util.js +++ b/app/backend/util.js @@ -60,30 +60,30 @@ export function flexibleEncodeComponent (str) { // Sometimes spaces screw things up because of url.parse str = str.replace(/%20/g, ' '); - let decodedPathname; + let decoded; try { - decodedPathname = decodeURIComponent(str); + decoded = decodeURIComponent(str); } catch (e) { // Malformed (probably not encoded) so assume it's decoded already - decodedPathname = str; + decoded = str; } - return encodeURIComponent(decodedPathname); + return encodeURIComponent(decoded); } export function flexibleEncode (str) { // Sometimes spaces screw things up because of url.parse str = str.replace(/%20/g, ' '); - let decodedPathname; + let decoded; try { - decodedPathname = decodeURI(str); + decoded = decodeURI(str); } catch (e) { // Malformed (probably not encoded) so assume it's decoded already - decodedPathname = str; + decoded = str; } - return encodeURI(decodedPathname); + return encodeURI(decoded); } export function prepareUrlForSending (url) { @@ -96,9 +96,10 @@ export function prepareUrlForSending (url) { // 1. Pathname // // ~~~~~~~~~~~ // - parsedUrl.pathname = flexibleEncode( - parsedUrl.pathname || '' - ); + if (parsedUrl.pathname) { + const segments = parsedUrl.pathname.split('/'); + parsedUrl.pathname = segments.map(flexibleEncodeComponent).join('/'); + } // ~~~~~~~~~~~~~~ // // 2. Querystring //