Skip to content

Commit

Permalink
fix demo server bug with hyphen characters
Browse files Browse the repository at this point in the history
  • Loading branch information
elvisduru committed Mar 19, 2024
1 parent 86223d7 commit d239007
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,17 @@ const generateSubDomain = (website?: string) => {
hostnameParts.pop();
// Remove the www subdomain
if (hostnameParts[0] === "www") hostnameParts.shift();
const result = hostnameParts.join("-");
const result = hostnameParts.join("");

// add a prefix if it starts with a number
const startsWithNumber = /^\d/.test(result);
if (startsWithNumber) return `demo-${result}`;
if (startsWithNumber) return `demo${result}`;

return result;
// escape special characters like hyphens
const escapedResult = result.replace(/[^a-zA-Z0-9-]/g, "").replace(/-/g, "");

if (escapedResult.length < 3) return generateUniqueString(10);
return escapedResult;
} catch {
return generateUniqueString(10);
}
Expand Down

0 comments on commit d239007

Please sign in to comment.