@actions/exec: `exec(commandLine)` drops `""` arguments and trims trailing spaces of the last argument

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

Maintainer thường phản hồi trong vòng 1 ngày

@bardrop đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #2577 của @bardrop — đang mở

Đánh giá

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

Hướng nghiên cứu

Bắt đầu với packages/exec/src/toolrunner.ts và kiểm tra argStringToArray, đặc biệt là cách hàm xử lý các đối số rỗng được đặt trong dấu ngoặc kép và đối số cuối cùng. Tái hiện các ví dụ trong issue bằng exec.exec hoặc exec.getExecOutput; công việc hoàn tất khi các đối số rỗng và khoảng trắng ở cuối được giữ nguyên trong cả ba trường hợp.

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

Mô tả

Describe the bug
When exec.exec (or exec.getExecOutput) is called with the command and arguments in a single commandLine string, argStringToArray silently drops any empty double-quoted argument ("") and trims trailing whitespace from the last argument only. A command like ssh-keygen -N "" -f key runs as ssh-keygen -N -f key, causing -f to be consumed as the value of -N.

To Reproduce

// repro.mjs
import * as exec from '@actions/exec'
const show = 'node -e "console.log(JSON.stringify(process.argv.slice(1)))" --'
await exec.exec(`${show} -N "" -f key`)
await exec.exec(`${show} -m "fix typo "`)
await exec.exec(`${show} -m "fix typo " x`)
npm i @actions/exec
node repro.mjs

Actual output:

[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -N -f key
["-N","-f","key"]
[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -m fix typo
["-m","fix typo"]
[command]/usr/bin/node -e console.log(JSON.stringify(process.argv.slice(1))) -- -m fix typo  x
["-m","fix typo ","x"]

Expected behavior

["-N","","-f","key"]
["-m","fix typo "]
["-m","fix typo ","x"]

Screenshots
Not applicable.

Desktop (please complete the following information):

  • OS: Linux x86_64
  • Browser: N/A
  • Version: @actions/exec 3.0.0 (actions/toolkit main 0c3a9c3), Node.js v26.13.0

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context
In packages/exec/src/toolrunner.ts, argStringToArray only pushes an argument when arg.length > 0 (so "" is discarded), and the final push after the loop uses arg.trim() while earlier pushes do not.

Credit: https://ucsbplse.github.io/

Ngôn ngữ chính
TypeScript
Star
5.9k
Fork
1.8k
Merge trung bình
15 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

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.

Issue khác của actions/toolkit

Tất cả issue của actions/toolkit

Issue tương tự

Thêm issue về TypeScript

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.