Repository navigation
Fix quarto.cmd altering arguments that contain ! or ^ - #15365
Merged
Merged
Conversation
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.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
quarto.cmdis 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 previewandquarto runthen fail on any file or project path containing!. This was found with an editor extension that startsquarto.cmd run server.ts <workspace>on a workspace path containing!.Every call through the dev
quarto.cmdis affected.quarto.exepasses its arguments to Deno directly and is not. The installedquarto.cmdhas 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.cmdenables 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 /Fvariable, and run with delayed expansion off:cmd substitutes a
FORvariable after parsing the line, so option variables such asQUARTO_DENO_EXTRA_OPTIONSstay 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, ...). TheDOclause 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 onmainsat inside anIFblock and failed that way too.The
--version,-vand--pathsshortcuts 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 throughcmd, aQUARTO_DENO_EXTRA_OPTIONSvalue 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.cmdwith a listing that still has the old launch line; a row indev-docs/runtime-migration/README.md"Open decisions with an owner" records it for that PR's step 0.Checklist
I have (if applicable):
AI-assisted PR
Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.