spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / tests / git / probes / is-safe-ref-name.test.ts
29 lines · 750 BRaw
1import { describe, expect, test, tier } from 'claude-code/testing'
2
3import Git from '../../../hooks/git'
4
5tier('builtin')
6
7describe('is-safe-ref-name', () => {
8 test('branch refs under refs/ pass', () => {
9 for (const ref of ['refs/heads/main', 'refs/heads/me/fh-diff_mod.2']) {
10 expect(Git.isSafeRefName(ref), ref).toBe(true)
11 }
12 })
13
14 test('climbing, absolute, backslashed, control or lock names fail', () => {
15 for (const ref of [
16 '',
17 'refs/../../etc/passwd',
18 '/refs/heads/main',
19 'refs\\heads\\main',
20 'refs/heads/ma\u001bin',
21 'refs/heads/main.lock',
22 'refs/heads/.hidden',
23 'heads/main',
24 'refs//main',
25 ]) {
26 expect(Git.isSafeRefName(ref), ref).toBe(false)
27 }
28 })
29})