From 39106e5c7d187576fbd196b1fe642310ed0118ab Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Wed, 11 Dec 2024 18:47:52 +0100 Subject: [PATCH] fix(alias): allow project name with invalid url characters (#44) --- vercel-deployment-task-source/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vercel-deployment-task-source/src/index.ts b/vercel-deployment-task-source/src/index.ts index 95256b7..1263a91 100644 --- a/vercel-deployment-task-source/src/index.ts +++ b/vercel-deployment-task-source/src/index.ts @@ -245,6 +245,10 @@ async function run() { getStagingPrefix(vercelOrgId, vercelToken), ]); const escapedBranchName = branchName.replace(/[^a-zA-Z0-9\-]-?/g, "-"); + const escapedProjectName = projectName.replace( + /[^a-zA-Z0-9\-]-?/g, + "-" + ); /** * Truncating branch name according to RFC 1035 if necessary * Maximum length is 63 characters. @@ -272,8 +276,8 @@ async function run() { * longer-project-name-feature-prefix-12346-my-second-f.vercel.app */ const branchNameAllowedLength = - 50 - projectName.length - stagingPrefix.length; - let aliasHostname = `${projectName}-${escapedBranchName}-${stagingPrefix}.vercel.app`; + 50 - escapedProjectName.length - stagingPrefix.length; + let aliasHostname = `${escapedProjectName}-${escapedBranchName}-${stagingPrefix}.vercel.app`; if (escapedBranchName.length > branchNameAllowedLength) { // Calculate the maximum length of the branchName by removing the stagingPrefix and the dash @@ -294,7 +298,7 @@ async function run() { } // Remove the stagingPrefix from the aliasHostname and use the extended aliasingBranchName - aliasHostname = `${projectName}-${aliasingBranchName}.vercel.app`; + aliasHostname = `${escapedProjectName}-${aliasingBranchName}.vercel.app`; } deployURL = `https://${aliasHostname}`;