microsoft / microsoft/vscode-python-debugger

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

Aperta Adatta ai principianti
#1,024 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

triage-needed
Lingua principale
TypeScript
Stelle
180
Fork
126
Merge medio
2g 3h
PR unite (30g)
3

Descrizione

Description:

When using the PowerShell wrapper script debugpy.ps1 to debug a Python script that accepts multiple command-line arguments, the arguments are not properly passed through to the Python script when provided as an array.

Steps to Reproduce:

  1. Create a test Python script (test.py):
import sys
print(sys.argv)
  1. Create a PowerShell script (run.ps1):
$arg_list = @('arg1', 'arg2')
$file = "test.py"

& python $file $arg_list  # Works correctly
& debugpy $file $arg_list  # Fails - arguments are concatenated
  1. Run the PowerShell script:
.\run.ps1

Actual Result:

['test.py', 'arg1', 'arg2']
['test.py', 'arg1 arg2']

Expected Result:

['test.py', 'arg1', 'arg2']
['test.py', 'arg1', 'arg2']

Root Cause:
The current debugpy.ps1 script passes $args directly to the Python command without using splatting (@args). When an array is passed to the script, PowerShell's $args receives it as a single object rather than expanding it into multiple arguments.

Current code:

if ($os -eq [System.PlatformID]::Win32NT) {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
}

Proposed Fix:
Use the splatting operator (@args) instead of $args to properly expand array arguments:

if ($os -eq [System.PlatformID]::Win32NT) {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal wrapper debugpy.ps1, concentrandoti su come il suo elenco di argomenti viene passato al comando Python in ogni ramo dell’OS. Riproduci il problema con gli script forniti run.ps1 e test.py, quindi verifica che gli argomenti array rimangano separati e producano l’output sys.argv previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
powershell, python
Ambito
cli
Tipo di issue
Bug
Difficoltà
1/5
Tempo stimato
1-3 ore
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
88/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.