cli: parseArgs() treats an empty flag value passed without "=" as a positional argument

未关闭 适合新手
#7,351 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@helmipradita 已经在做这个了。

开始于 2026年10月31日。

  • #7373 来自 @helmipradita —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
cli

调研方向

在@std/cli模块中找到parseArgs的实现(通常位于cli/parse_args.ts),查找为已定义的标志赋值并将未解析的参数添加到位置参数数组_的逻辑。调整条件,使作为标志值传入的空字符串不会被添加到_。运行现有的parseArgs测试套件(或添加一个与所提供的复现相匹配的测试),以确认函数在选项为{ string: ["foo"] }时,对输入["--foo", ""]返回{ _: [], foo: "" }。

由索引模型根据 Issue 内容生成。

描述

bug needs triage

Describe the bug

When an empty string is given as the value of a flag as a separate argument (--foo ""), parseArgs() sets the flag to "" but also pushes the same "" into _.

Steps to Reproduce

import { parseArgs } from "jsr:@std/[email protected]";

console.log(parseArgs(["--foo", ""], { string: ["foo"] }));
// Actual:   { _: [ "" ], foo: "" }
// Expected: { _: [], foo: "" }

Expected behavior

{ _: [], foo: "" } is returned. The empty string becomes the value of foo and does not appear in _.

Actual behavior

{ _: [ "" ], foo: "" } is returned. foo is "" as expected, but the same "" is also added to _.

Environment

  • OS: macOS 26.4.1
  • deno version: deno 2.9.7
  • std version: @std/cli 1.0.32
主要语言
TypeScript
星标
3.6k
派生
713
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

denoland/std 的其他 Issue

查看 denoland/std 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。