JsonNode.GetPath() and JsonException.Path produce `$..x` / `$.a.` for empty property names
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
路径由 JsonNode.GetPath() 和 JsonException.Path 构建,JsonObject.GetPath、ReadStack 和 WriteStack 中也做出同样的点号与方括号选择,它们依赖 ContainsSpecialCharacters()。从这里开始,并将空属性名视为需要使用方括号表示法。完成的标准是生成 $[''].x 和 $.a[''],并在 ParentPathRootTests 的 GetPath_EscapedPropertyNames 中新增一个测试用例。
由索引模型根据 Issue 内容生成。
描述
Description
An empty JSON property name is written with dot notation in paths, which gives $..x (JSONPath's descendant operator) and $.a.. Names with special characters already get bracket notation (e.g. $['a b'].x), and #122841 recently fixed their escaping, but an empty name still uses dot notation.
Reproduction Steps
using System.Text.Json;
using System.Text.Json.Nodes;
var root = JsonNode.Parse("""{"":{"x":1},"a":{"":2}}""")!;
Console.WriteLine(root[""]!["x"]!.GetPath());
Console.WriteLine(root["a"]![""]!.GetPath());
try
{
JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, int>>>("""{"":{"x":"nan"}}""");
}
catch (JsonException e)
{
Console.WriteLine(e.Path);
}
Expected behavior
$[''].x
$.a['']
$[''].x
Actual behavior
$..x
$.a.
$..x
Seen on .NET 10.0.15 and 11.0.0.
Other information
JsonObject.GetPath, ReadStack and WriteStack use bracket notation only when ContainsSpecialCharacters() is true, and that's ContainsAny(...), which is false for an empty span. RFC 9535's dot shorthand needs at least one character, so an empty member name can only be written as ['']. GetPath_EscapedPropertyNames in ParentPathRootTests doesn't include an empty name.
A possible fix is to treat an empty name as needing bracket notation in those three places, with an extra test case. I'm happy to send a PR.
- 主要语言
- C#
- 星标
- 18.5k
- 派生
- 5.8k
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 588
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/runtime 的其他 Issue
-
area-CodeGen-coreclr untriaged
难度 2/5 1-3 小时 新手友好度 65/100
dotnet/runtime#138181 · 1 条评论 ·
维护者通常 1 天内回复
-
area-System.Collections untriaged
难度 2/5 1-3 小时 新手友好度 82/100
dotnet/runtime#138090 · 1 条评论 ·
维护者通常 1 天内回复
-
area-Setup untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/runtime#137376 · 1 条评论 ·
维护者通常 1 天内回复
-
area-System.Memory untriaged
难度 2/5 1-3 小时 新手友好度 75/100
dotnet/runtime#137334 · 4 条评论 ·
维护者通常 1 天内回复
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by design可能已有人在做 @alaricd 于 18 天前认领。 未关闭area-System.Transactions untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/runtime#137040 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
area:identity type:bug
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug 🐞
难度 2/5 1-3 小时 新手友好度 72/100
valkey-io/valkey-glide#7849 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
bitfoundation/bitplatform#15455 ·
维护者通常 1 天内回复
-
area-Asset area-GameStudio area-Samples bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复