Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSonObjectAdapter test operation for empty string works inconsistent with standard definition #31

Closed
MateuszGert opened this issue Jul 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MateuszGert
Copy link

Hello, I've found some edge case:

[TestCase]
public void EmptyStringTest()
{
    var patchDocument = new JsonPatchDocument<JsonNode>();
    patchDocument.Operations.Add(new Operation<JsonNode>(op: "test", path: "/string", from: null, value: ""));
    var node = JsonNode.Parse("{\"string\": \"\"}")!;
    Assert.DoesNotThrow(() => patchDocument.ApplyTo(node));
}

[TestCase]
public void NullFieldTest()
{
    var patchDocument = new JsonPatchDocument<JsonNode>();
    patchDocument.Operations.Add(new Operation<JsonNode>(op: "test", path: "/string", from: null, value: null));
    var node = JsonNode.Parse("{\"string\": null}")!;
    Assert.DoesNotThrow(() => patchDocument.ApplyTo(node));
}

From https://datatracker.ietf.org/doc/html/rfc6902#section-4.6

The "test" operation tests that a value at the target location is
equal to a specified value.
The operation object MUST contain a "value" member that conveys the
value to be compared to the target location's value.
The target location MUST be equal to the "value" value for the
operation to be considered successful.
Here, "equal" means that the value at the target location and the
value conveyed by "value" are of the same JSON type, and that they
are considered equal by the following rules for that type:
o strings: are considered equal if they contain the same number of
Unicode characters and their code points are byte-by-byte equal.
(...)
o literals (false, true, and null): are considered equal if they are
the same.

@Havunen Havunen added the bug Something isn't working label Jul 6, 2024
Havunen added a commit that referenced this issue Aug 7, 2024
@Havunen
Copy link
Owner

Havunen commented Aug 7, 2024

This is fixed in v3.2.1

@Havunen Havunen closed this as completed Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants