Skip to content

Commit 80e964c

Browse files
Bugfix: Update regex for valid branch names (#10356)
1 parent 0c04da9 commit 80e964c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.changeset/giant-ghosts-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: Update regex for valid branch name to remove 61 char length requirement, allowing for longer branch names to be specified for preview aliases.

packages/wrangler/src/__tests__/versions/versions.upload.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,21 +484,16 @@ describe("generatePreviewAlias", () => {
484484
expect(result).toBeUndefined();
485485
});
486486

487-
it("handles complex branch names with truncation", () => {
488-
const scriptName = "myworker";
489-
const complexBranch =
490-
"feat/JIRA-12345/implement-awesome-new-feature-with-detail";
487+
it("handles long branch names with truncation", () => {
488+
const scriptName = "longer-branch-name-worker";
489+
const longBranch = "a".repeat(100);
491490
mockExecSync
492491
.mockImplementationOnce(() => {}) // is-inside-work-tree
493-
.mockImplementationOnce(() => Buffer.from(complexBranch));
492+
.mockImplementationOnce(() => Buffer.from(longBranch));
494493

495494
const result = generatePreviewAlias(scriptName);
496495

497496
expect(result).toBeDefined();
498-
expect(result).toMatch(
499-
/^feat-jira-12345-implement-awesome-new-feature-wit-[a-f0-9]{4}$/
500-
);
501-
expect(result?.length).toBe(54);
502497
expect(result).not.toBeUndefined();
503498
expect((scriptName + "-" + result).length).toBeLessThanOrEqual(63);
504499
});

packages/wrangler/src/versions/upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ function formatTime(duration: number) {
905905
// Constants for DNS label constraints and hash configuration
906906
const MAX_DNS_LABEL_LENGTH = 63;
907907
const HASH_LENGTH = 4;
908-
const ALIAS_VALIDATION_REGEX = /^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
908+
const ALIAS_VALIDATION_REGEX = /^[a-z](?:[a-z0-9-]*[a-z0-9])?$/i;
909909

910910
/**
911911
* Sanitizes a branch name to create a valid DNS label alias.

0 commit comments

Comments
 (0)