Skip to content

Commit

Permalink
fix(normaliseUrlDomain): allow custom url scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
zaosoula committed Jun 3, 2024
1 parent dc0badb commit f6c37a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 3 additions & 11 deletions lib/build/normalisedURLDomain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions lib/ts/normalisedURLDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class NormalisedURLDomain {
};
}

function normaliseURLDomainOrThrowError(input: string, ignoreProtocol = false): string {
function normaliseURLDomainOrThrowError(input: string): string {
input = input.trim().toLowerCase();

// if the input starts with a . (eg: .domain.tld)
Expand All @@ -36,7 +36,7 @@ function normaliseURLDomainOrThrowError(input: string, ignoreProtocol = false):
}

// if the input dosen't start with a protocol add a default one;
if (input.match(/^[^:]:\/\//)) {
if (!input.match(/^[^:]+:\/\//)) {
if (input.startsWith("localhost") || isAnIpAddress(input)) {
input = "http://" + input;
} else {
Expand All @@ -47,15 +47,7 @@ function normaliseURLDomainOrThrowError(input: string, ignoreProtocol = false):
try {
const urlObj = new URL(input);

if (ignoreProtocol) {
if (urlObj.hostname.startsWith("localhost") || isAnIpAddress(urlObj.hostname)) {
return "http://" + urlObj.host;
} else {
return "https://" + urlObj.host;
}
} else {
return urlObj.protocol + "//" + urlObj.host;
}
return urlObj.protocol + "//" + urlObj.host;
} catch {
throw Error("Please provide a valid domain name");
}
Expand Down

0 comments on commit f6c37a6

Please sign in to comment.