From e47f45df0c42f75a2d0fd81c1d0ec78d25506fd3 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 3 Nov 2026 18:17:30 +0100 Subject: [PATCH] Quote paths in dev quarto.cmd so it runs from a checkout path with spaces In dev mode the launcher called win_configuration.bat unquoted, so cmd split the checkout path at the first space and DENO stayed empty. The stale-Deno check then fired on every run: it overwrote config/deno-version with the localized "ECHO is off." text and asked the user to retry, and the corrupted file stayed behind afterwards. Quoting that call exposed two more breaks further down the same path: the final launch line passed the deno executable and quarto.ts unquoted, and QUARTO_IMPORT_MAP_ARG wrapped the import map path in doubled quotes, which Deno parses as an unquoted path. The import map argument goes back to single inner quotes, the form it had before the conda plumbing change switched it to the doubled form without a stated reason. The --lock argument added with the Deno lockfile copied the doubled form and fails the same way, so it gets single inner quotes too. The `cd` in the stale-Deno branch is quoted for consistency, although `cd` already accepts an unquoted path with spaces. The bundled branch of the launcher is left unchanged; quarto.exe is the entry point there. The test runs quarto.cmd through a junction whose name contains a space and checks that config/deno-version still holds the configured Deno version. It disables current-directory command lookup for the child so that a regression reaching the stale-Deno branch cannot run configure.cmd against the checkout under test. --- package/scripts/windows/quarto.cmd | 10 +- .../unit/dev-launcher-path-with-space.test.ts | 95 +++++++++++++++++++ 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 tests/unit/dev-launcher-path-with-space.test.ts diff --git a/package/scripts/windows/quarto.cmd b/package/scripts/windows/quarto.cmd index e4c897f35bb..6183f4b00aa 100644 --- a/package/scripts/windows/quarto.cmd +++ b/package/scripts/windows/quarto.cmd @@ -32,7 +32,7 @@ IF EXIST "!QUARTO_TS_PATH!" ( GOTO end ) - call !QUARTO_ROOT!\win_configuration.bat + call "!QUARTO_ROOT!\win_configuration.bat" REM overrride share path to point to our dev folder instead of dist set QUARTO_SHARE_PATH=!QUARTO_ROOT!\src\resources set "DENO_DIR=!QUARTO_BIN_PATH!\deno_cache" @@ -40,11 +40,11 @@ IF EXIST "!QUARTO_TS_PATH!" ( IF NOT DEFINED QUARTO_ACTION ( SET QUARTO_ACTION=run ) - SET "QUARTO_IMPORT_MAP_ARG=--importmap=""!QUARTO_SRC_PATH!\import_map.json""" + SET "QUARTO_IMPORT_MAP_ARG=--importmap="!QUARTO_SRC_PATH!\import_map.json"" REM Resolve dependencies through the checked-in lockfile, as vendoring does. REM Without it, Deno re-resolves npm packages, which needs registry metadata that REM the vendored cache doesn't contain (and may pick versions other than the pinned ones). - SET "QUARTO_LOCK_OPTIONS=--lock=""!QUARTO_ROOT!\deno.lock"" --frozen" + SET "QUARTO_LOCK_OPTIONS=--lock="!QUARTO_ROOT!\deno.lock" --frozen" IF NOT DEFINED QUARTO_TARGET ( SET "QUARTO_TARGET=!QUARTO_TS_PATH!" @@ -63,7 +63,7 @@ IF EXIST "!QUARTO_TS_PATH!" ( if NOT "!DENO!"=="!DENO_INSTALLED_VERSION!" ( echo !DENO!>"!DENO_VERSION_FILE!" - cd !QUARTO_ROOT! + cd "!QUARTO_ROOT!" call configure.cmd echo echo. @@ -172,7 +172,7 @@ IF DEFINED QUARTO_TS_PROFILE ( ) IF DEFINED QUARTO_DEV_MODE ( - !QUARTO_DENO! !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_IMPORT_MAP_ARG! !QUARTO_TARGET! %* + "!QUARTO_DENO!" !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_IMPORT_MAP_ARG! "!QUARTO_TARGET!" %* ) ELSE ( !QUARTO_DENO! !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_TARGET! %* ) diff --git a/tests/unit/dev-launcher-path-with-space.test.ts b/tests/unit/dev-launcher-path-with-space.test.ts new file mode 100644 index 00000000000..5db5dbee518 --- /dev/null +++ b/tests/unit/dev-launcher-path-with-space.test.ts @@ -0,0 +1,95 @@ +/* + * dev-launcher-path-with-space.test.ts + * + * The dev launcher package/dist/bin/quarto.cmd must work when the checkout + * path contains a space. + * + * Copyright (C) 2026 Posit Software, PBC + */ + +import { unitTest } from "../test.ts"; +import { assert, assertEquals } from "../asserts.ts"; +import { isWindows } from "../../src/deno_ral/platform.ts"; +import { dirname, fromFileUrl, join } from "../../src/deno_ral/path.ts"; +import { + existsSync, + readTextFileSync, + removeSync, + writeTextFileSync, +} from "../../src/deno_ral/fs.ts"; +import { execProcess } from "../../src/core/process.ts"; +import { withTempDir } from "../utils.ts"; + +const repoRoot = join(dirname(fromFileUrl(import.meta.url)), "..", ".."); +const denoVersionFile = join(repoRoot, "package", "dist", "config", "deno-version"); + +// The DENO version from the `configuration` file, which win_configuration.bat +// exports and the launcher records in config/deno-version. +function configuredDenoVersion(): string { + const configuration = readTextFileSync(join(repoRoot, "configuration")); + const match = configuration.match(/^export DENO=(\S+)/m); + assert(match, "DENO not found in configuration"); + return match[1]; +} + +unitTest( + "dev-launcher - quarto.cmd runs from a checkout path containing a space", + async () => { + const denoVersionBefore = existsSync(denoVersionFile) + ? readTextFileSync(denoVersionFile) + : undefined; + await withTempDir(async (dir) => { + const junction = join(dir, "with space"); + const mklink = await execProcess({ + cmd: "cmd", + args: ["/c", "mklink", "/J", junction, repoRoot], + stdout: "piped", + stderr: "piped", + }); + assert(mklink.success, `creating the junction failed: ${mklink.stderr}`); + try { + const result = await execProcess({ + cmd: join(junction, "package", "dist", "bin", "quarto.cmd"), + args: ["--help"], + cwd: dir, + stdout: "piped", + stderr: "piped", + env: { + QUARTO_NO_TYPECHECK: "true", + // A failed launch can reach the stale-Deno branch, which runs + // `call configure.cmd` from the checkout root. Disabling + // current-directory command lookup keeps it from reconfiguring + // the checkout under test. + NoDefaultCurrentDirectoryInExePath: "1", + }, + }); + const stdout = result.stdout ?? ""; + const stderr = result.stderr ?? ""; + const denoVersionAfter = existsSync(denoVersionFile) + ? readTextFileSync(denoVersionFile) + : undefined; + // The launcher writes the file on first run, so it may not have + // existed before; either way it must hold the configured version. + assertEquals( + denoVersionAfter?.trim(), + configuredDenoVersion(), + "config/deno-version does not hold the configured Deno version", + ); + assert( + result.success && stdout.includes("Usage:"), + `quarto.cmd --help failed (exit ${result.code})\nstdout:\n${stdout}\nstderr:\n${stderr}`, + ); + } finally { + // Restore a deno-version the launcher may have corrupted, then remove + // the junction itself (not its target) before the temp dir goes. + if (denoVersionBefore !== undefined) { + writeTextFileSync(denoVersionFile, denoVersionBefore); + } else if (existsSync(denoVersionFile)) { + removeSync(denoVersionFile); + } + removeSync(junction); + } + }); + }, + { ignore: !isWindows, requiresDevQuarto: true }, +);