(command: string, isJq = false)
| 126 | } |
| 127 | |
| 128 | function extractQuotedContent(command: string, isJq = false): QuoteExtraction { |
| 129 | let withDoubleQuotes = '' |
| 130 | let fullyUnquoted = '' |
| 131 | let unquotedKeepQuoteChars = '' |
| 132 | let inSingleQuote = false |
| 133 | let inDoubleQuote = false |
| 134 | let escaped = false |
| 135 | |
| 136 | for (let i = 0; i < command.length; i++) { |
| 137 | const char = command[i] |
| 138 | |
| 139 | if (escaped) { |
| 140 | escaped = false |
| 141 | if (!inSingleQuote) withDoubleQuotes += char |
| 142 | if (!inSingleQuote && !inDoubleQuote) fullyUnquoted += char |
| 143 | if (!inSingleQuote && !inDoubleQuote) unquotedKeepQuoteChars += char |
| 144 | continue |
| 145 | } |
| 146 | |
| 147 | if (char === '\\' && !inSingleQuote) { |
| 148 | escaped = true |
| 149 | if (!inSingleQuote) withDoubleQuotes += char |
| 150 | if (!inSingleQuote && !inDoubleQuote) fullyUnquoted += char |
| 151 | if (!inSingleQuote && !inDoubleQuote) unquotedKeepQuoteChars += char |
| 152 | continue |
| 153 | } |
| 154 | |
| 155 | if (char === "'" && !inDoubleQuote) { |
| 156 | inSingleQuote = !inSingleQuote |
| 157 | unquotedKeepQuoteChars += char |
| 158 | continue |
| 159 | } |
| 160 | |
| 161 | if (char === '"' && !inSingleQuote) { |
| 162 | inDoubleQuote = !inDoubleQuote |
| 163 | unquotedKeepQuoteChars += char |
| 164 | // For jq, include quotes in extraction to ensure content is properly analyzed |
| 165 | if (!isJq) continue |
| 166 | } |
| 167 | |
| 168 | if (!inSingleQuote) withDoubleQuotes += char |
| 169 | if (!inSingleQuote && !inDoubleQuote) fullyUnquoted += char |
| 170 | if (!inSingleQuote && !inDoubleQuote) unquotedKeepQuoteChars += char |
| 171 | } |
| 172 | |
| 173 | return { withDoubleQuotes, fullyUnquoted, unquotedKeepQuoteChars } |
| 174 | } |
| 175 | |
| 176 | function stripSafeRedirections(content: string): string { |
| 177 | // SECURITY: All three patterns MUST have a trailing boundary (?=\s|$). |
no outgoing calls
no test coverage detected