JsonObject's ICollection<KeyValuePair<string, JsonNode?>>.Remove ignores the value
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
Empieza en JsonObject.IDictionary.cs, en el método explícito ICollection<KeyValuePair<string, JsonNode?>>.Remove, que actualmente llama a Remove(item.Key) sin comprobar el valor. Compáralo con el método Contains justo encima, que comprueba la clave y la referencia del nodo. Añade una prueba en JsonObjectTests para una clave coincidente con un valor distinto y ejecuta esa clase de pruebas. Está terminado cuando ese caso devuelve false y deja la propiedad en su sitio, mientras que un par coincidente sigue eliminándose y desvinculándose.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
JsonObject's explicit ICollection<KeyValuePair<string, JsonNode?>>.Remove(item) removes the property with the matching key even when the value doesn't match. Contains(item) on the same interface does check the value, and Dictionary<,> and OrderedDictionary<,> return false from Remove in this case.
Reproduction Steps
using System.Text.Json.Nodes;
var obj = new JsonObject { ["a"] = 1, ["b"] = 2 };
ICollection<KeyValuePair<string, JsonNode?>> collection = obj;
var other = new KeyValuePair<string, JsonNode?>("b", JsonValue.Create(99));
Console.WriteLine(collection.Contains(other));
Console.WriteLine(collection.Remove(other));
Console.WriteLine(obj.ToJsonString());
Expected behavior
False
False
{"a":1,"b":2}
Actual behavior
False
True
{"a":1}
Seen on .NET 10.0.15 and 11.0.0. For comparison, ((ICollection<KeyValuePair<string, int>>)new Dictionary<string, int> { ["a"] = 1, ["b"] = 2 }).Remove(new("b", 99)) returns false and keeps both entries, and so does OrderedDictionary<string, int>.
Other information
In JsonObject.IDictionary.cs the method is => Remove(item.Key);, while its XML docs say it removes "the property name and value" represented by the KeyValuePair. Contains right above it documents that it checks the property name and JsonNode reference, and it does: a different node with an equal value also returns false. The existing test in JsonObjectTests removes a pair that matches and a key that doesn't exist, but not a matching key with a different value.
A possible fix is to return false unless Contains(item) is true (so the same reference semantics as Contains), then remove by key as today so the node is still detached from its parent. I can send a PR with a test if you'd like.
- Lenguaje dominante
- C#
- Estrellas
- 18.5k
- Forks
- 5.8k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 588
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/runtime
-
area-CodeGen-coreclr untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
dotnet/runtime#138181 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-System.Text.Json untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/runtime#138089 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-Setup untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dotnet/runtime#137376 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-System.Memory untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
dotnet/runtime#137334 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designPosiblemente ocupada @alaricd la tomó hace 18 días. Abiertoarea-System.Transactions untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/runtime#137040 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/runtime
Issues similares
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
area:identity type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
bug 🐞
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
valkey-io/valkey-glide#7849 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bitfoundation/bitplatform#15455 ·
Los mantenedores suelen responder en 1 día
-
area-Asset area-GameStudio area-Samples bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día