Skip to content

Commit

Permalink
fix(frontend): fix method to parse url (#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc authored Sep 6, 2023
1 parent 1feaf9b commit 3c5196c
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions web/src/utils/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,10 @@ export const getIsValidUrl = (url: string): boolean => {
}
};

const regex =
'(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$';

export const getParsedURL = (rawUrl: string): URL => {
const urlRegex = new RegExp(regex, 'i');

const [matchedUrl = ''] = rawUrl.match(urlRegex) || [];

if (!matchedUrl) throw new Error('Invalid URL');

if (!!matchedUrl && !matchedUrl.startsWith('http')) {
return new URL(`http://${matchedUrl}`);
if (!!rawUrl && !rawUrl.startsWith('http')) {
return new URL(`http://${rawUrl}`);
}

return new URL(matchedUrl);
return new URL(rawUrl);
};

0 comments on commit 3c5196c

Please sign in to comment.