MCPcopy Index your code
hub / github.com/codeaashu/claude-code / isLinePrintingCommand

Function isLinePrintingCommand

src/tools/BashTool/sedValidation.ts:44–117  ·  view source on GitHub ↗
(
  command: string,
  expressions: string[],
)

Source from the content-addressed store, hash-verified

42 * @internal Exported for testing
43 */
44export function isLinePrintingCommand(
45 command: string,
46 expressions: string[],
47): boolean {
48 const sedMatch = command.match(/^\s*sed\s+/)
49 if (!sedMatch) return false
50
51 const withoutSed = command.slice(sedMatch[0].length)
52 const parseResult = tryParseShellCommand(withoutSed)
53 if (!parseResult.success) return false
54 const parsed = parseResult.tokens
55
56 // Extract all flags
57 const flags: string[] = []
58 for (const arg of parsed) {
59 if (typeof arg === 'string' && arg.startsWith('-') && arg !== '--') {
60 flags.push(arg)
61 }
62 }
63
64 // Validate flags - only allow -n, -E, -r, -z and their long forms
65 const allowedFlags = [
66 '-n',
67 '--quiet',
68 '--silent',
69 '-E',
70 '--regexp-extended',
71 '-r',
72 '-z',
73 '--zero-terminated',
74 '--posix',
75 ]
76
77 if (!validateFlagsAgainstAllowlist(flags, allowedFlags)) {
78 return false
79 }
80
81 // Check if -n flag is present (required for Pattern 1)
82 let hasNFlag = false
83 for (const flag of flags) {
84 if (flag === '-n' || flag === '--quiet' || flag === '--silent') {
85 hasNFlag = true
86 break
87 }
88 // Check in combined flags
89 if (flag.startsWith('-') && !flag.startsWith('--') && flag.includes('n')) {
90 hasNFlag = true
91 break
92 }
93 }
94
95 // Must have -n flag for Pattern 1
96 if (!hasNFlag) {
97 return false
98 }
99
100 // Must have at least one expression
101 if (expressions.length === 0) {

Callers 1

Calls 4

tryParseShellCommandFunction · 0.85
isPrintCommandFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected