Value.Patch: "add" with an out-of-range array index appends instead of failing
评估
调研方向
先在 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tailscale/hujson 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Standardize modifies its input slice; the doc comment does not say so可能已有人在做 @jihtsan 于 29 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 60/100
-
难度 2/5 1-3 小时 新手友好度 68/100
-
Value.Patch: "test" operation always fails for a null value可能已有人在做 @RaphaelFakhri 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
-
Patching with comments可能已有人在做 @Shubham-Padkonde 于 47 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
cpp-best-practices/project_validator#259 ·
维护者通常 1 天内回复
-
Add Gather未关闭addition
难度 2/5 1-3 小时 新手友好度 62/100
awesome-selfhosted/awesome-selfhosted-data#3323 ·
维护者通常 1 天内回复
-
tech-debt
难度 2/5 半天 新手友好度 72/100
维护者通常 1 天内回复
-
area: interop area: sip-core v3
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复