Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw when passing an object with no protocol #917

Merged
merged 1 commit into from Nov 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions source/normalize-arguments.ts
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
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