|
7 | 7 | import os from 'node:os'; |
8 | 8 | import fs from 'node:fs'; |
9 | 9 | import path from 'node:path'; |
10 | | -import { quote, type ParseEntry } from 'shell-quote'; |
| 10 | +import { quote, parse, type ParseEntry } from 'shell-quote'; |
11 | 11 | import { |
12 | 12 | spawn, |
13 | 13 | spawnSync, |
@@ -846,10 +846,26 @@ export function stripShellWrapper(command: string): string { |
846 | 846 | if (match) { |
847 | 847 | let newCommand = command.substring(match[0].length).trim(); |
848 | 848 | if ( |
849 | | - (newCommand.startsWith('"') && newCommand.endsWith('"')) || |
850 | | - (newCommand.startsWith("'") && newCommand.endsWith("'")) |
| 849 | + newCommand.length >= 2 && |
| 850 | + ((newCommand.startsWith('"') && newCommand.endsWith('"')) || |
| 851 | + (newCommand.startsWith("'") && newCommand.endsWith("'"))) |
851 | 852 | ) { |
852 | | - newCommand = newCommand.substring(1, newCommand.length - 1); |
| 853 | + const isPosixShell = match[0].trim().endsWith('-c'); |
| 854 | + if (isPosixShell && newCommand.startsWith('"')) { |
| 855 | + try { |
| 856 | + const parsed = parse(newCommand, (key) => '$' + key); |
| 857 | + const firstEntry = parsed[0]; |
| 858 | + if (parsed.length === 1 && typeof firstEntry === 'string') { |
| 859 | + newCommand = firstEntry; |
| 860 | + } else { |
| 861 | + newCommand = newCommand.substring(1, newCommand.length - 1); |
| 862 | + } |
| 863 | + } catch { |
| 864 | + newCommand = newCommand.substring(1, newCommand.length - 1); |
| 865 | + } |
| 866 | + } else { |
| 867 | + newCommand = newCommand.substring(1, newCommand.length - 1); |
| 868 | + } |
853 | 869 | } |
854 | 870 | return newCommand; |
855 | 871 | } |
|
0 commit comments