mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix(branch): collapse empty path segments in branch_name_template (#1539)
A branch_name_template that places {{description}} (or another variable)
next to a slash crashes the run when the variable resolves to an empty
string. An issue/PR title with no ASCII-alphanumeric content — emoji-only,
CJK-only, or punctuation-only — makes extractDescription() return "", so a
template like "{{prefix}}{{description}}/{{entityNumber}}" produces
"claude//123". validateBranchName rejects consecutive (and leading/trailing)
slashes, and the thrown error propagates uncaught out of setupBranch,
aborting the entire run.
Normalize the templated result before the empty-result check: collapse runs
of slashes and drop any leading/trailing slash. Single-slash and dash
separators are untouched, so existing template behavior is unchanged; a
template that collapses to empty still falls back to the default format.
This is distinct from the {{label}} sanitization tracked in #1491 (and its
open PRs), which deliberately leave {{description}} alone — so this path
remained broken. Fixes the whole empty-segment class regardless of variable.
Adds regression tests for emoji-only and CJK-only titles, a trailing empty
segment, and a direct validateBranchName assertion proving the run no longer
aborts.
This commit is contained in:
@@ -72,6 +72,21 @@ export function applyBranchTemplate(
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapses empty path segments produced when a template variable resolves to
|
||||
* an empty string. For example, an issue title with no alphanumeric characters
|
||||
* (emoji-only, CJK-only, or punctuation-only) makes `{{description}}` empty, so
|
||||
* a template like `{{prefix}}{{description}}/{{entityNumber}}` yields
|
||||
* `claude//123`. Consecutive slashes — and a leading or trailing slash — are
|
||||
* rejected by `validateBranchName`, which aborts the whole run, so normalize
|
||||
* them into a valid branch name instead of crashing.
|
||||
*/
|
||||
function collapseEmptyPathSegments(branchName: string): string {
|
||||
return branchName
|
||||
.replace(/\/{2,}/g, "/") // collapse runs of slashes left by empty segments
|
||||
.replace(/^\/+|\/+$/g, ""); // drop leading/trailing slashes
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a branch name from the provided `template` and set of `variables`. Uses a default format if the template is empty or produces an empty result.
|
||||
*/
|
||||
@@ -97,7 +112,9 @@ export function generateBranchName(
|
||||
};
|
||||
|
||||
if (template?.trim()) {
|
||||
const branchName = applyBranchTemplate(template, variables);
|
||||
const branchName = collapseEmptyPathSegments(
|
||||
applyBranchTemplate(template, variables),
|
||||
);
|
||||
|
||||
// Some templates could produce empty results- validate
|
||||
if (branchName.trim().length > 0) return branchName;
|
||||
|
||||
Reference in New Issue
Block a user