Skip to content

Fix debugpy.ps1 argument forwarding with splatting (@args) - #1146

Open
TEJA P C (PCTEJA) wants to merge 1 commit into
microsoft:mainfrom
PCTEJA:fix-debugpy-ps1-splatting-1024
Open

TEJA P C (PCTEJA) wants to merge 1 commit into
microsoft:mainfrom
PCTEJA:fix-debugpy-ps1-splatting-1024

Conversation

@PCTEJA

Copy link
Copy Markdown

Summary

Fixes #1024.

The PowerShell no-config wrapper bundled/scripts/noConfigScripts/debugpy.ps1 forwarded $args without splatting, so when a caller passed an array of arguments, they reached the Python process concatenated as a single string:

$arg_list = @('arg1', 'arg2')
& debugpy test.py $arg_list   # sys.argv -> ['test.py', 'arg1 arg2']  (wrong)
& python  test.py $arg_list   # sys.argv -> ['test.py', 'arg1', 'arg2'] (correct)

Change

Use splatting (@args) in both invocations in debugpy.ps1 (Windows python branch and non-Windows python3 branch). Two lines changed; nothing else.

Testing

Reproduced and verified with PowerShell 7.4.6 using a stub adapter script that prints sys.argv:

  • Before: ["--listen", "0", "--wait-for-client", "test.py", "arg1 arg2"]
  • After: ["--listen", "0", "--wait-for-client", "test.py", "arg1", "arg2"]
  • Also verified after the fix: single arguments containing spaces ("my script.py", "one arg") remain single arguments, and invoking with no extra arguments works.

The patch was also independently reviewed with Codex (GPT-6 Astra), which re-ran the reproduction across argument-passing modes (42 argv comparisons, all passing) and confirmed splatting semantics for Windows PowerShell 5.1 and PowerShell 7 from Microsoft's documentation. Windows PowerShell 5.1 was not runtime-tested locally (no Windows host available).

This change was prepared with AI assistance (Muse, validated with Codex); I have reviewed every changed line and take responsibility for it.

The PowerShell no-config wrapper forwarded $args without splatting,
so an array of arguments passed by a caller reached the Python
process concatenated as a single string (e.g. 'arg1 arg2' instead of
two separate argv entries).

Use @Args in both the Windows (python) and non-Windows (python3)
invocations so array arguments expand into separate arguments,
matching how the caller could pass them to python directly.

Fixes microsoft#1024
@PCTEJA

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

PowerShell script debugpy.ps1 incorrectly handles multiple arguments passed as an array

1 participant