| |
| |
| |
| |
| |
|
|
| import { describe, it, expect } from 'vitest'; |
| import os from 'node:os'; |
| import { ShellExecutionService } from './shellExecutionService.js'; |
| import { NoopSandboxManager } from './sandboxManager.js'; |
|
|
| const isWindows = os.platform() === 'win32'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| describe.skipIf(!isWindows)( |
| 'ShellExecutionService Windows quoting (real shell)', |
| () => { |
| const baseConfig = { |
| sanitizationConfig: { |
| allowedEnvironmentVariables: [], |
| blockedEnvironmentVariables: [], |
| enableEnvironmentVariableRedaction: false, |
| }, |
| sandboxManager: new NoopSandboxManager(), |
| }; |
|
|
| async function runReal(command: string) { |
| const controller = new AbortController(); |
| const handle = await ShellExecutionService.execute( |
| command, |
| process.cwd(), |
| () => {}, |
| controller.signal, |
| false, |
| baseConfig, |
| ); |
| const result = await handle.result; |
| return { result, output: result.output }; |
| } |
|
|
| it('should preserve inline double quotes through node -e', async () => { |
| const { result, output } = await runReal( |
| `node -e 'console.log("preserved")'`, |
| ); |
| expect(result.exitCode).toBe(0); |
| expect(output).toBe('preserved'); |
| }); |
|
|
| it('should preserve double quotes inside JSON output', async () => { |
| const { result, output } = await runReal( |
| `node -e 'console.log(JSON.stringify({ok:"yes"}))'`, |
| ); |
| expect(result.exitCode).toBe(0); |
| expect(output).toBe('{"ok":"yes"}'); |
| }); |
|
|
| it('should handle quoted argument containing a space', async () => { |
| const { result, output } = await runReal( |
| `node -e "console.log('hello world')"`, |
| ); |
| expect(result.exitCode).toBe(0); |
| expect(output).toBe('hello world'); |
| }); |
|
|
| it('should handle a mixed-quote regex literal', async () => { |
| const { result, output } = await runReal( |
| `node -e 'console.log(String("a").match(/"/))'`, |
| ); |
| expect(result.exitCode).toBe(0); |
| expect(output).toBe('null'); |
| }); |
|
|
| it('should pass a literal double-quote byte through to stdout', async () => { |
| const { result, output } = await runReal(`node -e 'console.log("\\"")'`); |
| expect(result.exitCode).toBe(0); |
| expect(output).toBe('"'); |
| }); |
| }, |
| ); |
|
|