Skip to content

Commit

Permalink
fix: component -> string returns incorrect values when an non-object …
Browse files Browse the repository at this point in the history
…is passed
  • Loading branch information
Michael committed Oct 21, 2022
1 parent ad97426 commit 8b2b198
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/core/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
combineStrings,
forEach,
merge,
isFunction
isFunction,
isEmpty
} from "../utils";

type URLStringBuilder = Pick<
Expand All @@ -33,13 +34,17 @@ type URLStringBuilder = Pick<

/**
* Test if a url string has a valid protocol.
*
* Most likely going to deprecate this function.
*/
export function isProtocolURL(url: string): boolean {
return PROTOCOL_REGEXP.test(url);
}

/**
* Test if a url string has a valid hostname.
*
* Most likely going to deprecate this function.
*/
export function isHostnameURL(url: string): boolean {
return HOSTNAME_REGEXP.test(url);
Expand Down Expand Up @@ -92,6 +97,10 @@ export function convertURIComponentToString(input: URLStringBuilder): string {
);
}

if (argumentIsNotProvided(input) || isEmpty(input) || !isObject(input)) {
return "";
}

forEach(input, (key, value) => {
const regex = createRegexString(key);

Expand Down Expand Up @@ -140,7 +149,7 @@ export function uriParser(
}
} else if (isObject(uri)) {
// prettier-ignore
const protocol = extractMatchFromRegExp(uri.protocol, PROTOCOL_REGEXP, 0) as URLProtocol;
const protocol = extractMatchFromRegExp(uri.protocol, PROTOCOL_REGEXP, 0, "http") as URLProtocol;
// prettier-ignore
const hostname = stringReplacer(uri.hostname, new RegExp(`^${protocol}://`, "gi"), "");

Expand Down

0 comments on commit 8b2b198

Please sign in to comment.