Skip to content

Commit

Permalink
Check for unsupported characters first
Browse files Browse the repository at this point in the history
  • Loading branch information
jafeltra committed Mar 6, 2024
1 parent 50584b3 commit 9dcef55
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/optimizer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export function resolveAliasFromURL(url: string, aliases: ExportableAlias[]): st
if (rawAlias == null) {
return;
}
// Ensure the generated alias is unique
const aliasPart = `$${rawAlias}`;
// Ensure the generated alias contains only supported characters and is unique
const aliasPart = `$${rawAlias.replace(unsupportedAliasCharRegex, '-')}`;
let counterPart = 0;
let alias = aliasPart;
const existingAliases = aliases.map(a => a.alias);
Expand All @@ -104,9 +104,6 @@ export function resolveAliasFromURL(url: string, aliases: ExportableAlias[]): st
alias = `${aliasPart}_${counterPart}`;
}

// Replace unsupported characters, but allow $ at the start
alias = `$${alias.substring(1).replace(unsupportedAliasCharRegex, '-')}`;

aliases.push(new ExportableAlias(alias, url));
return alias;
}
Expand Down

0 comments on commit 9dcef55

Please sign in to comment.