refactor(gitref): 將分支名稱驗證改為正式模組

This commit is contained in:
Jeffery
2026-07-21 16:26:30 +08:00
parent 76617dd9dc
commit 1f012c6cfb
3 changed files with 39 additions and 45 deletions
+3 -2
View File
@@ -4,14 +4,15 @@ const assert = require('node:assert/strict');
const test = require('node:test');
const gitrepo = require('../src/lib/gitrepo');
const gitref = require('../src/lib/gitref');
test('assertSafeBranchRef 接受一般分支名稱', () => {
assert.equal(gitrepo.__test.assertSafeBranchRef('feature/review-123', 'baseRef'), 'feature/review-123');
assert.equal(gitref.assertSafeBranchRef('feature/review-123', 'baseRef'), 'feature/review-123');
});
test('assertSafeBranchRef 拒絕路徑穿越分支名稱', () => {
assert.throws(
() => gitrepo.__test.assertSafeBranchRef('../../hooks/pre-push', 'baseRef'),
() => gitref.assertSafeBranchRef('../../hooks/pre-push', 'baseRef'),
/不是安全的分支名稱/,
);
});