← Back to Pull requests

Fix commandline quoting when elevating new tabs #20939

Closed
unknown closed this pull request without merging on Nov 24, 2026 19:08 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 03:43 UTC
Author

Summary of the Pull Request

Fixes how the commandline is passed to the elevated window when opening an elevated profile from an unelevated one. Today pwsh.exe -NoLogo arrives as a single argument ("pwsh.exe -NoLogo") and fails with 0x80070002.

References and Relevant Issues

#12597, possibly #14861

Detailed Description of the Pull Request / Additional comments

ToCommandline() wrapped the whole commandline in one pair of quotes without escaping. The elevated instance parses it with CommandLineToArgvW, so the commandline came back as one quoted argument, and a quoted path like "C:\Program Files\..." was split at the first space.

The commandline is now appended unquoted after --, escaping only ; so it isn't treated as a subcommand delimiter. The receiver then splits it back into the original arguments, the same way it does for wt new-tab -- <commandline>.

Known pre-existing limitation, also with direct wt usage: some quoting (e.g. \", "") isn't preserved exactly when args are re-joined; I can address that in a follow-up.

To reproduce: add "elevate": true to the Command Prompt profile, then from an unelevated shell run wt -p "Command Prompt" cmd.exe /k echo hi. The elevated window fails to launch "cmd.exe /k echo hi" with error 0x80070002.

I used an AI agent (Copilot CLI + Claude Opus 5.5) to help investigate and write this change. I reviewed, built, and tested it myself.

Validation Steps Performed

  • Updated TestGenerateCommandline and added a ; case. All SettingsModel unit tests pass.

  • Added TestElevatedCommandlineRoundTrip to LocalTests. It serializes NewTerminalArgs with ToCommandline(), parses the result like the elevated instance does, and checks the commandline is unchanged. It fails without the fix.

  • Manually opened an elevated profile from an unelevated dev build with:

  • - pwsh.exe -NoLogo -NoProfile -EncodedCommand ...
    - "C:\Program Files\PowerShell\7\pwsh.exe" -NoExit -Command "echo 'a b'\; echo c"

    Both launched correctly. Both fail on the current release.

    PR Checklist


  • Closes #12597

  • Tests added/passed

  • [N/A] Documentation updated

  • - If checked, please file a pull request on our docs repo and link it here: #xxx
  • [N/A] Schema updated (if necessary)
  • Diff: 290 lines (+217 / -73) across 3 files Reviewer: DHowett Review duration: 6684m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 290 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #20939"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.2% · Safe to merge
    17.2%