Skip to content

Commit

Permalink
Make the url option mutually exclusive with the input argument
Browse files Browse the repository at this point in the history
Fixes #985
  • Loading branch information
szmarczak committed Dec 27, 2019
1 parent 5008bf7 commit e0f8aab
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/normalize-arguments.ts
Original file line number Diff line number Diff line change
@@ -234,6 +234,10 @@ export const normalizeArguments = (url: URLOrOptions, options?: Options, default
}

if (is.urlInstance(url) || is.string(url)) {
if (Reflect.has(options, 'url')) {
throw new TypeError('The `url` option cannot be used if the input is valid URL.');
}

// @ts-ignore URL is not URL
options.url = url;

6 changes: 6 additions & 0 deletions test/arguments.ts
Original file line number Diff line number Diff line change
@@ -357,3 +357,9 @@ test('throws if `options.encoding` is `null`', async t => {
encoding: null
}), 'To get a Buffer, set `options.responseType` to `buffer` instead');
});

test('`url` option and input argument are mutually exclusive', async t => {
await t.throwsAsync(got('https://example.com', {
url: 'https://example.com'
}), 'The `url` option cannot be used if the input is valid URL.');
});

0 comments on commit e0f8aab

Please sign in to comment.