JsonNode.GetPath() and JsonException.Path produce `$..x` / `$.a.` for empty property names
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il percorso viene costruito da JsonNode.GetPath() e JsonException.Path, e la stessa scelta tra notazione a punto e notazione a parentesi quadre viene fatta in JsonObject.GetPath, ReadStack e WriteStack, che si basano su ContainsSpecialCharacters(). Inizia da lì e considera un nome di proprietà vuoto come un caso che richiede la notazione a parentesi quadre. Il lavoro è completato quando vengono prodotti $[''].x e $.a[''] e viene aggiunto un nuovo caso a GetPath_EscapedPropertyNames in ParentPathRootTests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 18.5k
- Fork
- 5.8k
- Merge medio
- 2g 18h
- PR unite (30g)
- 588
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dotnet/runtime
-
area-CodeGen-coreclr untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
dotnet/runtime#138181 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-System.Collections untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
dotnet/runtime#138090 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-Setup untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
dotnet/runtime#137376 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area-System.Memory untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
dotnet/runtime#137334 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designForse già presa @alaricd l’ha presa 18 giorni fa. Apertaarea-System.Transactions untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dotnet/runtime#137040 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di dotnet/runtime
Issue simili
-
needs-area-label
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
area:identity type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
bug 🐞
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
valkey-io/valkey-glide#7849 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bitfoundation/bitplatform#15455 ·
I maintainer di solito rispondono entro 1 giorno
-
area-Asset area-GameStudio area-Samples bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno