Skip to content

Fix quarto.cmd altering arguments that contain ! or ^ - #15365

Merged
cderv merged 4 commits into
mainfrom
fix/quarto-cmd-delayed-expansion
Nov 13, 2026
Merged

cderv merged 4 commits into
mainfrom
fix/quarto-cmd-delayed-expansion

Conversation

@cderv

@cderv cderv commented Nov 13, 2026

Copy link
Copy Markdown
Member

Description

When quarto.cmd is called with an argument containing !, the argument reaches Quarto altered. A lone ! is dropped, text between two ! is replaced by the environment variable of that name (even across two arguments), and ^ is dropped. quarto render, quarto preview and quarto run then fail on any file or project path containing !. This was found with an editor extension that starts quarto.cmd run server.ts <workspace> on a workspace path containing !.

Every call through the dev quarto.cmd is affected. quarto.exe passes its arguments to Deno directly and is not. The installed quarto.cmd has the same launch line since at least 1.10, so direct calls to it are affected too.

Follows #15276 and #15288, which fixed the same launcher for paths containing a space.

Root cause

quarto.cmd enables delayed expansion (!VAR! variables, read when a line runs) and forwarded the arguments with %* on a line built from !VAR!. cmd substitutes %* first, then rescans the whole line for !, so the arguments went through that second pass too.

Fix

The Deno command is built from the script's variables with delayed expansion on, carried through a FOR /F variable, and run with delayed expansion off:

FOR /F "delims=" %%C IN ("!QUARTO_DENO_CMD!") DO SETLOCAL DISABLEDELAYEDEXPANSION & %%C %*

cmd substitutes a FOR variable after parsing the line, so option variables such as QUARTO_DENO_EXTRA_OPTIONS stay literal even when they contain & or ^, and the arguments skip the ! pass. Expanding the variables with %VAR% was deemed unsafe for that reason. ENDLOCAL & ... was not used either, as it drops the variables the script sets for Deno (DENO_DIR, QUARTO_SHARE_PATH, NO_COLOR, ...). The DO clause has no parentheses, since a ) in an argument typed unquoted at a terminal (quarto.cmd render report(1).qmd) would close them. The launch line on main sat inside an IF block and failed that way too.

The --version, -v and --paths shortcuts now compare "%~1". Deno quotes every argument it passes to a batch file, so "%1" became ""--version"" and never matched, and a first argument containing & crashed the script.

A Windows-only unit test runs the dev and the bundled layout with arguments containing ! ^ & % () and spaces, an unquoted command line through cmd, a QUARTO_DENO_EXTRA_OPTIONS value containing & ^ !, and the three shortcuts.

An install or checkout path containing ! or ^ still breaks the launcher, because that path goes through delayed expansion before any argument is used. This is left for a separate change.

Runtime migration plan 33 replaces quarto.cmd with a listing that still has the old launch line; a row in dev-docs/runtime-migration/README.md "Open decisions with an owner" records it for that PR's step 0.

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Claude Code
  • Codebase grounding: local clone
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

quarto.cmd enables delayed expansion and forwarded %* on a line that
used !VAR!. %* is substituted before delayed expansion runs, so the
arguments were rescanned: an unmatched "!" was dropped, text between
two "!" (even across separate arguments) was expanded as a variable
name, and "^" was stripped. Rendering, previewing or running a file
whose path contains "!" failed with the dev build, and any caller
that starts quarto.cmd by name (terminal, IDE extensions) was
affected. quarto.exe passes its arguments to Deno directly and is not.

- Launch Deno under SETLOCAL DISABLEDELAYEDEXPANSION with %VAR%. The
  nested SETLOCAL keeps every variable the script set, which
  ENDLOCAL & would have dropped. One launch line now serves the dev
  and bundled layouts; the bundled branch clears
  QUARTO_IMPORT_MAP_ARG so an inherited value cannot reach Deno.
- Compare "%~1" in the --version, -v and --paths short-circuits. Deno
  quotes every argument it passes to a batch file, so "%1" became
  ""--version"" and never matched, and a first argument containing &
  crashed the script.
- Add a Windows-only test that runs both layouts with arguments
  containing ! ^ & % () and spaces, a first argument containing &,
  and the three short-circuits.

An install or checkout path containing "!" or "^" still breaks the
launcher; that path goes through delayed expansion before any
argument is used, and is left for a separate change.
Expanding the option variables with %VAR% on the launch line let cmd
parse their values: QUARTO_DENO_EXTRA_OPTIONS=--location=http://x/?a=1&b=2
split the Deno command at the "&", and an unquoted "^" was consumed.
!VAR! had inserted these values after cmd parsed the line.

Build the Deno command with !VAR! instead, carry it through a FOR /F
variable, which cmd also substitutes after parsing, and run it with
delayed expansion off so %* still reaches Deno unchanged. The test now
also passes a QUARTO_DENO_EXTRA_OPTIONS value containing & ^ and !.
The FOR /F body that launches Deno was a parenthesized block, so a ")"
in an argument typed unquoted at a terminal (quarto.cmd render
report(1).qmd) closed it and cmd failed with ".qmd was unexpected".
The launch line on main sat inside an IF/ELSE block and failed the same
way.

The DO clause is now a single line: SETLOCAL DISABLEDELAYEDEXPANSION &
%%C %*. cmd applies delayed expansion to each command when it runs, so
%* still reaches Deno with delayed expansion off. The test now also
runs quarto.cmd through cmd with an unquoted command line.
@posit-snyk-bot

posit-snyk-bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Plan 33 Task 9 Step 4 replaces quarto.cmd with a full listing written
before #15276 and this fix. Pasted as is, it would bring back the
argument corruption, the "%1" shortcuts and the unquoted
win_configuration.bat call. Per the migration AGENTS.md, the finding
goes in the open-decisions table for PR 33's step 0, not into the plan.
@cderv
cderv merged commit 1782b5b into main Nov 13, 2026
52 checks passed
@cderv
cderv deleted the fix/quarto-cmd-delayed-expansion branch November 13, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants