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

Function validateFlagsAgainstAllowlist

src/tools/BashTool/sedValidation.ts:13–35  ·  view source on GitHub ↗

* Helper: Validate flags against an allowlist * Handles both single flags and combined flags (e.g., -nE) * @param flags Array of flags to validate * @param allowedFlags Array of allowed single-character and long flags * @returns true if all flags are valid, false otherwise

(
  flags: string[],
  allowedFlags: string[],
)

Source from the content-addressed store, hash-verified

11 * @returns true if all flags are valid, false otherwise
12 */
13function validateFlagsAgainstAllowlist(
14 flags: string[],
15 allowedFlags: string[],
16): boolean {
17 for (const flag of flags) {
18 // Handle combined flags like -nE or -Er
19 if (flag.startsWith('-') && !flag.startsWith('--') && flag.length > 2) {
20 // Check each character in combined flag
21 for (let i = 1; i < flag.length; i++) {
22 const singleFlag = '-' + flag[i]
23 if (!allowedFlags.includes(singleFlag)) {
24 return false
25 }
26 }
27 } else {
28 // Single flag or long flag
29 if (!allowedFlags.includes(flag)) {
30 return false
31 }
32 }
33 }
34 return true
35}
36
37/**
38 * Pattern 1: Check if this is a line printing command with -n flag

Callers 2

isLinePrintingCommandFunction · 0.85
isSubstitutionCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected