From d239007f21c1dc1adf351851831aac928b254372 Mon Sep 17 00:00:00 2001 From: elvisduru Date: Tue, 19 Mar 2024 14:11:50 +0300 Subject: [PATCH] fix demo server bug with hyphen characters --- src/mail/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mail/index.ts b/src/mail/index.ts index f02e6c7..7cadafe 100644 --- a/src/mail/index.ts +++ b/src/mail/index.ts @@ -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); }