From 025f4f2d3e0c6a679e27b7ea8b58f7e7e71ac011 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Wed, 1 Apr 2020 17:39:01 +0200 Subject: [PATCH] Fix #1113 --- source/core/index.ts | 7 +++++++ test/arguments.ts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/source/core/index.ts b/source/core/index.ts index 385cb5c70..c6b48042a 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -701,6 +701,13 @@ export default class Request extends Duplex implements RequestEvents { options.url = new URL(`http://unix${options.url.pathname}${options.url.search}`); } + if (options.url.search) { + const triggerSearchParams = '_GOT_INTERNAL_TRIGGER_NORMALIZATION'; + + options.url.searchParams.append(triggerSearchParams, ''); + options.url.searchParams.delete(triggerSearchParams); + } + if (protocol !== 'http:' && protocol !== 'https:') { throw new UnsupportedProtocolError(options as NormalizedOptions); } diff --git a/test/arguments.ts b/test/arguments.ts index 081808699..3db1f687d 100644 --- a/test/arguments.ts +++ b/test/arguments.ts @@ -455,3 +455,11 @@ test('does not throw on frozen options', withServer, async (t, server, got) => { t.is(body, '/'); }); + +test('normalizes search params included in input', t => { + const {url} = got.mergeOptions({ + url: new URL('https://example.com/?a=b c') + }); + + t.is(url.search, '?a=b+c'); +});