Value.Patch: "add" with an out-of-range array index appends instead of failing

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

@SashaMIT 已经在做这个了。

开始于 2026年10月12日。

  • #53 来自 @RaphaelFakhri —— 已关闭,未合并
  • #55 来自 @SashaMIT —— 未关闭

评估

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

调研方向

先在 patch.go 中阅读 patchAdd 和 find,然后使用报告中的 Go 示例重现该问题。如果有现成的 patch 相关测试,请检查它们。完成的标准是:当 add 操作的 index 大于数组长度时返回错误并保持数组不变,而 index 等于长度以及 - token 仍然会追加。

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

描述

What happened

An add operation whose array index is greater than the array length succeeds and appends the value.

v, _ := hujson.Parse([]byte(`[1,2]`))
err := v.Patch([]byte(`[{"op":"add","path":"/5","value":3}]`))
fmt.Println(err, string(v.Pack()))
// <nil> [1,2,3]

What you expected

RFC 6902, section 4.1 states that the index of an add on an array must not be greater than the number of elements. The patch should fail with an error and leave the array unchanged. Indexes equal to the length and the - token continue to append.

Cause

patchAdd in patch.go accepts any errNotFound from find as an insertion point. For arrays, find reports the array length as the index for every missing index, so /5 is treated the same as /2 or /-.

主要语言
Go
星标
892
派生
40
PR 合并指标
30 天内没有已合并 PR

环境准备

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

从这里开始

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

tailscale/hujson 的其他 Issue

查看 tailscale/hujson 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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