microsoft / microsoft/vscode-python-debugger

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

Đang mở Phù hợp với người mới
#1,024 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

triage-needed
Ngôn ngữ chính
TypeScript
Star
180
Fork
126
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
3

Mô tả

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
}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong wrapper debugpy.ps1, tập trung vào cách danh sách đối số của nó được truyền đến lệnh Python trong từng nhánh OS. Tái hiện vấn đề bằng các script run.ps1 và test.py được cung cấp, sau đó xác minh rằng các đối số mảng vẫn tách biệt và tạo ra đầu ra sys.argv như mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell, python
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
1/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
88/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.