fix: allow , in branch names#1310
Open
bugbubug wants to merge 1 commit into
Open
Conversation
`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 anthropics#1167 and `+` in anthropics#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 anthropics#1300
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
validateBranchNameinsrc/github/operations/branch.tsrejects branch names containing a comma (,), even thoughgit check-ref-formatpermits commas and GitHub itself accepts them when creating the branch. When the action runs on a PR whose head branch contains a,, validation throws before any git operation and the action fails immediately:This shows up in real workflows when branch 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.Fixes #1300.
Root cause
The whitelist regex at
src/github/operations/branch.ts:66is:,is not in the character class, so any ref containing one is rejected regardless of position.The whitelist exists for injection safety, but every git call in this file uses
execFileSyncwith an argv array (no shell, no interpolation), so,carries no injection risk under that execution model. This is the same reasoning used to add#in #1167 and+in #1248.Fix
Add
,to the whitelist:/^[a-zA-Z0-9][a-zA-Z0-9/_.#+,-]*$/. Update the surrounding comment and the user-facing error message to match.Testing
feature/a,b,feature/paris,france,fix/issue-1,2,3)bun test: 666 pass, 0 failbun run typecheck: cleanbun run format:check: clean