Reject consecutive slashes and dot-prefixed components in branch validation

This commit is contained in:
Denis Darii 2026-04-03 15:28:59 +02:00
parent f92c5f6c9d
commit 034de8a3fa
2 changed files with 7 additions and 0 deletions

View File

@ -106,6 +106,11 @@ describe("isGitBranchNameSafe", () => {
expect(isGitBranchNameSafe(".hidden")).toBe(false);
});
it("rejects consecutive slashes and dot-prefixed components", () => {
expect(isGitBranchNameSafe("feat//bar")).toBe(false);
expect(isGitBranchNameSafe("feat/.hidden")).toBe(false);
});
it("rejects characters invalid in git refs", () => {
expect(isGitBranchNameSafe("bad branch")).toBe(false);
expect(isGitBranchNameSafe("x:y")).toBe(false);

View File

@ -44,6 +44,8 @@ export function isGitBranchNameSafe(name: string): boolean {
if (name === "@" || name.startsWith(".") || name.endsWith(".") || name.endsWith("/")) return false;
if (name.endsWith(".lock")) return false;
if (name.includes("..")) return false;
if (name.includes("//")) return false;
if (name.includes("/.")) return false;
if (name.includes("@{")) return false;
if (name.startsWith("/")) return false;
for (let i = 0; i < name.length; i++) {