diff --git a/ui/desktop/src/platform/windows/bin/npx.cmd b/ui/desktop/src/platform/windows/bin/npx.cmd index 6558c57ec..71ef6fe33 100644 --- a/ui/desktop/src/platform/windows/bin/npx.cmd +++ b/ui/desktop/src/platform/windows/bin/npx.cmd @@ -10,6 +10,8 @@ SET "MIN_SYSTEM_NODE_MAJOR=22" REM === Check for previously downloaded portable Node.js (matching version) === if exist "%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed" ( SET "PATH=%GOOSE_NODE_DIR%;!PATH!" + REM Turn delayed expansion off before npx runs, or cmd reads ! in the arguments as a variable. + SETLOCAL DisableDelayedExpansion "%GOOSE_NODE_DIR%\npx.cmd" %* exit /b !errorlevel! ) @@ -24,6 +26,7 @@ for /f "delims=" %%N in ('where $PATH:node.exe 2^>nul') do ( call "%%~dpNnpx.cmd" --version nul 2>&1 if "!errorlevel!"=="0" ( SET "PATH=%%~dpN;!PATH!" + SETLOCAL DisableDelayedExpansion "%%~dpNnpx.cmd" %* exit /b !errorlevel! ) @@ -57,6 +60,7 @@ if exist "%GOOSE_NODE_DIR%\npx.cmd" ( echo.>"%GOOSE_NODE_DIR%\node-v%NODE_VERSION%.installed" SET "PATH=%GOOSE_NODE_DIR%;!PATH!" echo [Goose] Node.js v%NODE_VERSION% ready. 1>&2 + SETLOCAL DisableDelayedExpansion "%GOOSE_NODE_DIR%\npx.cmd" %* exit /b !errorlevel! ) diff --git a/ui/desktop/src/platform/windows/npx.test.ts b/ui/desktop/src/platform/windows/npx.test.ts index 3248cecc9..1b984b1e8 100644 --- a/ui/desktop/src/platform/windows/npx.test.ts +++ b/ui/desktop/src/platform/windows/npx.test.ts @@ -146,6 +146,17 @@ describe.skipIf(process.platform !== 'win32')('Windows npx wrapper', () => { expect((JSON.parse(result.stdout) as ChildReport).nodeDir).toBe(systemNodeDir); }); + it.each<[string, () => { pathDirs: string[]; goosePortableDir?: string }]>([ + ['the downloaded Node.js', () => ({ pathDirs: [], goosePortableDir: portableNodeDir })], + ['a system Node.js', () => ({ pathDirs: [systemNodeDir] })], + ])('keeps ! and ^ in the arguments with %s', (_name, setup) => { + const args = ['-y', 'pkg', '--token=abc!123', '--pattern=a^b!c', 'x!']; + const result = runWrapper({ ...setup(), args }); + + expect(result.status).toBe(0); + expect((JSON.parse(result.stdout) as ChildReport).args).toEqual(args); + }); + it('propagates the npx exit status', () => { const result = runWrapper({ pathDirs: [systemNodeDir], args: ['-y', 'pkg'], exitCode: 37 });