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

Function quoteShellCommand

source code/utils/bash/shellQuoting.ts:48–76  ·  view source on GitHub ↗
(
  command: string,
  addStdinRedirect: boolean = true,
)

Source from the content-addressed store, hash-verified

46 * @returns The properly quoted command
47 */
48export function quoteShellCommand(
49 command: string,
50 addStdinRedirect: boolean = true,
51): string {
52 // If command contains heredoc or multiline strings, handle specially
53 // The shell-quote library incorrectly escapes ! to \! in these cases
54 if (containsHeredoc(command) || containsMultilineString(command)) {
55 // For heredocs and multiline strings, we need to quote for eval
56 // but avoid shell-quote's aggressive escaping
57 // We'll use single quotes and escape only single quotes in the command
58 const escaped = command.replace(/'/g, "'\"'\"'")
59 const quoted = `'${escaped}'`
60
61 // Don't add stdin redirect for heredocs as they provide their own input
62 if (containsHeredoc(command)) {
63 return quoted
64 }
65
66 // For multiline strings without heredocs, add stdin redirect if needed
67 return addStdinRedirect ? `${quoted} < /dev/null` : quoted
68 }
69
70 // For regular commands, use shell-quote
71 if (addStdinRedirect) {
72 return quote([command, '<', '/dev/null'])
73 }
74
75 return quote([command])
76}
77
78/**
79 * Detects if a command already has a stdin redirect

Callers 1

buildExecCommandFunction · 0.85

Calls 3

containsMultilineStringFunction · 0.85
quoteFunction · 0.85
containsHeredocFunction · 0.70

Tested by

no test coverage detected