mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: Encode branch names in URLs to prevent truncation in markdown links
Branch names containing special characters (particularly parentheses) were breaking markdown links in GitHub comments. This caused URLs to be truncated when clicked. Changes: - Add encodeBranchName() helper function that: - Uses encodeURIComponent for basic encoding - Preserves forward slashes (GitHub expects literal / in branch URLs) - Manually encodes parentheses (not encoded by encodeURIComponent per RFC 3986) - Apply encoding to branch URLs in: - update-comment-link.ts (PR compare URLs) - branch-cleanup.ts (branch tree URLs) - comment-logic.ts (branch tree URLs) - comments/common.ts (branch tree URLs) - Improve PR link regex to use greedy match with end anchor - Add test for branch names with special characters
This commit is contained in:
@@ -139,6 +139,21 @@ describe("updateCommentBody", () => {
|
||||
);
|
||||
expect(result).not.toContain("View branch");
|
||||
});
|
||||
|
||||
it("encodes special characters in branch names while preserving slashes", () => {
|
||||
const input = {
|
||||
...baseInput,
|
||||
branchName: "feature/fix(issue)-test",
|
||||
};
|
||||
|
||||
const result = updateCommentBody(input);
|
||||
// Branch name display should show the original name
|
||||
expect(result).toContain("`feature/fix(issue)-test`");
|
||||
// URL should have encoded parentheses but preserved slashes
|
||||
expect(result).toContain(
|
||||
"https://github.com/owner/repo/tree/feature/fix%28issue%29-test",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PR link", () => {
|
||||
|
||||
Reference in New Issue
Block a user