Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions source/normalize-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ export const normalizeArguments = (url: URLOrOptions, options: Options, defaults
urlObj = urlArgument;
}

// Override both null/undefined with default protocol
options = mergeOptions({path: ''}, urlObj, {protocol: urlObj.protocol || 'https:'}, options);
if (!Reflect.has(urlObj, 'protocol') && !Reflect.has(options, 'protocol')) {
throw new TypeError('No URL protocol specified');
}

options = mergeOptions(urlObj, options);

for (const hook of options.hooks.init) {
if (is.asyncFunction(hook)) {
Expand Down
5 changes: 5 additions & 0 deletions test/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ test('throws an error if the protocol is not specified', async t => {
instanceOf: TypeError,
message: 'Invalid URL: example.com'
});

await t.throwsAsync(got({}), {
instanceOf: TypeError,
message: 'No URL protocol specified'
});
});

test('string url with searchParams is preserved', withServer, async (t, server, got) => {
Expand Down