Skip to content

Commit

Permalink
Add protocol to custom URLs if it's missing, encode replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
tfedor committed Dec 10, 2024
1 parent ec87489 commit da2daeb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/Core/Utils/UrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
export default class UrlUtils {

public static escapeUserUrl(url: string, replacements: Record<string, string>): string {
if (!/^[^/]+\/\//.test(url)) {
url = `https://${url}`;
}

for (const [pattern, replacement] of Object.entries(replacements)) {
url = url.replace(`[${pattern}]`, replacement);
url = url.replace(`[${pattern}]`, encodeURIComponent(replacement));
}
return (new URL(url)).toString();
}
Expand Down

0 comments on commit da2daeb

Please sign in to comment.