Skip to content

Commit

Permalink
fix(alias): allow project name with invalid url characters (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs authored Dec 11, 2024
1 parent a1a5f55 commit 39106e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vercel-deployment-task-source/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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}`;
Expand Down

0 comments on commit 39106e5

Please sign in to comment.