From b0919ef7a4758e1069c906d6d46b678850f7fb9c Mon Sep 17 00:00:00 2001 From: Giuseppe B <20780192+MrSnix@users.noreply.github.com> Date: Fri, 11 Jun 2021 12:46:51 +0200 Subject: [PATCH] Fix dollar not correctly handled on URI (#2862) Co-authored-by: Dimitri Mitropoulos Co-authored-by: Opender Singh --- packages/insomnia-url/src/querystring.test.ts | 16 ++++++++++++---- packages/insomnia-url/src/querystring.ts | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/insomnia-url/src/querystring.test.ts b/packages/insomnia-url/src/querystring.test.ts index 4ea67447a..9ca38918b 100644 --- a/packages/insomnia-url/src/querystring.test.ts +++ b/packages/insomnia-url/src/querystring.test.ts @@ -178,13 +178,13 @@ describe('querystring', () => { }); it('leaves already encoded pathname', () => { - const url = smartEncodeUrl('https://google.com/foo%20bar%20baz/100%25/foo'); - expect(url).toBe('https://google.com/foo%20bar%20baz/100%25/foo'); + const url = smartEncodeUrl('https://google.com/foo%20bar%20baz/100%25/foo/%24'); + expect(url).toBe('https://google.com/foo%20bar%20baz/100%25/foo/%24'); }); it('encodes querystring', () => { - const url = smartEncodeUrl('https://google.com?s=foo bar 100%&hi'); - expect(url).toBe('https://google.com/?s=foo%20bar%20100%25&hi'); + const url = smartEncodeUrl('https://google.com?s=foo bar 100%&hi$'); + expect(url).toBe('https://google.com/?s=foo%20bar%20100%25&hi%24'); }); it('encodes querystring with mixed spaces', () => { @@ -205,6 +205,14 @@ describe('querystring', () => { // Encoded should skip encoded versions of @ ; , const url2 = smartEncodeUrl('https://google.com/%40%3B%2C%26%5E'); expect(url2).toBe('https://google.com/%40%3B%2C%26%5E'); + + // Encoded should skip raw versions of $ + const url3 = smartEncodeUrl('https://google.com/$myservice'); + expect(url3).toBe('https://google.com/$myservice'); + + // Encoded should skip encoded versions of $ + const url4 = smartEncodeUrl('https://google.com/%24myservice'); + expect(url4).toBe('https://google.com/%24myservice'); }); it('leaves already encoded characters alone', () => { diff --git a/packages/insomnia-url/src/querystring.ts b/packages/insomnia-url/src/querystring.ts index cc75a4bb8..99419bb72 100644 --- a/packages/insomnia-url/src/querystring.ts +++ b/packages/insomnia-url/src/querystring.ts @@ -2,7 +2,15 @@ import { parse as urlParse, format as urlFormat } from 'url'; import { setDefaultProtocol } from './protocol'; const ESCAPE_REGEX_MATCH = /[-[\]/{}()*+?.\\^$|]/g; -const URL_PATH_CHARACTER_WHITELIST = '+,;@=:'; + +/** see list of allowed characters https://datatracker.ietf.org/doc/html/rfc3986#section-2.2 */ +const RFC_3986_GENERAL_DELIMITERS = ':@'; // (unintentionally?) missing: /?#[] + +/** see list of allowed characters https://datatracker.ietf.org/doc/html/rfc3986#section-2.2 */ +const RFC_3986_SUB_DELIMITERS = '$+,;='; // (unintentionally?) missing: !&'()* + +/** see list of allowed characters https://datatracker.ietf.org/doc/html/rfc3986#section-2.2 */ +const URL_PATH_CHARACTER_WHITELIST = `${RFC_3986_GENERAL_DELIMITERS}${RFC_3986_SUB_DELIMITERS}`; export const getJoiner = (url: string) => { url = url || '';