Skip to content

Commit

Permalink
Fix and simplify URL custom URLs handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tfedor committed Dec 10, 2024
1 parent c90d9f9 commit e129490
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/js/Core/Utils/UrlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@
export default class UrlUtils {

public static escapeUserUrl(url: string, replacements: Record<string, string>): string {
const result = new URL(url);

/*
* For some reason
* for (const ... of result.searchParams.entries())
* does not work, and I have no idea why (says it's not iterable)
*/

result.searchParams.forEach((value, name, searchParams) => {
for (const [pattern, replacement] of Object.entries(replacements)) {
value = value.replace(`[${pattern}]`, replacement);
}
searchParams.set(name, value);
});
return result.toString();
for (const [pattern, replacement] of Object.entries(replacements)) {
url = url.replace(`[${pattern}]`, replacement);
}
return (new URL(url)).toString();
}
}

0 comments on commit e129490

Please sign in to comment.