Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf6d40e

Browse files
authored
fix: allow , in branch names (#1310)
`validateBranchName` rejects branch names containing a comma, even though `git check-ref-format` permits commas and GitHub itself accepts them. PRs whose head branch contains a `,` fail validation in-process before any git operation, so the action errors out immediately. Branch names with commas show up in real workflows when names are derived from titles, place names, or external identifiers (e.g. "feature/paris,france"). There is no workaround other than renaming the branch, which is often not under the user's control. All git calls in this file use execFileSync with an argv array, so no shell interpretation occurs and `,` carries no injection risk. This is the same reasoning used to add `#` in #1167 and `+` in #1248. - Add `,` to the validateBranchName whitelist regex - Update the surrounding comment and error message to match - Add a test case covering commas in title-derived branch names Fixes #1300
1 parent 86eb26b commit bf6d40e

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/github/operations/branch.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,18 @@ export function validateBranchName(branchName: string): void {
5858
);
5959
}
6060

61-
// Strict whitelist pattern: alphanumeric start, then alphanumeric/slash/hyphen/underscore/period/hash/plus.
61+
// Strict whitelist pattern: alphanumeric start, then alphanumeric/slash/hyphen/underscore/period/hash/plus/comma.
6262
// # is valid per git-check-ref-format and commonly used in branch names like "fix/#123-description".
6363
// + is valid per git-check-ref-format and generated by Claude Code's EnterWorktree tool when
6464
// converting worktree names containing "/" (e.g. "feat/foo" becomes "worktree-feat+foo").
65-
// All git calls use execFileSync (not shell interpolation), so neither # nor + carries injection risk.
66-
const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9/_.#+-]*$/;
65+
// , is valid per git-check-ref-format and commonly appears in branch names derived from titles
66+
// or external identifiers (e.g. place names like "feature/paris,france").
67+
// All git calls use execFileSync (not shell interpolation), so none of these characters carry injection risk.
68+
const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9/_.#+,-]*$/;
6769

6870
if (!validPattern.test(branchName)) {
6971
throw new Error(
70-
`Invalid branch name: "${branchName}". Branch names must start with an alphanumeric character and contain only alphanumeric characters, forward slashes, hyphens, underscores, periods, hashes (#), or plus signs (+).`,
72+
`Invalid branch name: "${branchName}". Branch names must start with an alphanumeric character and contain only alphanumeric characters, forward slashes, hyphens, underscores, periods, hashes (#), plus signs (+), or commas (,).`,
7173
);
7274
}
7375

test/validate-branch-name.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ describe("validateBranchName", () => {
5555
expect(() => validateBranchName("fix+issue-123")).not.toThrow();
5656
expect(() => validateBranchName("feature+new-thing")).not.toThrow();
5757
});
58+
59+
it("should accept branch names containing , (git-valid, common in title-derived branches)", () => {
60+
// Reported in #1300: branches like "feature/a,b" were rejected, even though
61+
// git check-ref-format and GitHub both accept commas. Common when branch names
62+
// are derived from titles, place names, or external identifiers.
63+
expect(() => validateBranchName("feature/a,b")).not.toThrow();
64+
expect(() => validateBranchName("feature/paris,france")).not.toThrow();
65+
expect(() => validateBranchName("fix/issue-1,2,3")).not.toThrow();
66+
});
5867
});
5968

6069
describe("command injection attempts", () => {

0 commit comments

Comments
 (0)