Invalid JSON in `CMD` is rewritten to exec form

已关闭 适合新手
#79 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

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

调研方向

首先在Go源代码中找到CMD处理逻辑和JSON参数解析,然后阅读CMD格式化测试。复现CMD ["a",]这个情况,并检查当参数不是有效的JSON数组时,格式化会保持原样。添加回归测试,并确认它通过项目的测试套件。

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

描述

CMD with an argument list that is not valid JSON gets wrapped into exec form. Docker treats such a line as shell form, so the rewrite changes the command the container runs.

Reproduce
FROM scratch
CMD ["a",]
dockerfmt Dockerfile
Actual
FROM scratch
CMD ["[\"a\",]"]

BuildKit's parser (v0.33.0) reads the original as shell form (/bin/sh -c '["a",]'). The output is exec form that runs a binary literally named ["a",].

Expected

Leave arguments that do not parse as a JSON array unchanged, as Docker does.

Reproduced with v0.5.4 and with main at a5868c2.

主要语言
Go
星标
626
派生
23
平均合并
3 天 17 小时
30 天内合并 PR
9

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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