Skip to content

JsonPatch - Tests on empty string throws exception #28019

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

Closed
Kjelli opened this issue Nov 20, 2020 · 4 comments
Closed

JsonPatch - Tests on empty string throws exception #28019

Kjelli opened this issue Nov 20, 2020 · 4 comments
Labels
affected-few This issue impacts only small number of customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-json-patch ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate severity-blocking This label is used by an internal tool Status: Resolved

Comments

@Kjelli
Copy link

Kjelli commented Nov 20, 2020

Describe the bug

I want to overwrite an existing json property that is an empty string "", and beforehand a test operation is performed. When testing that the value at path /foo is equal to "" - an exception is thrown with the following error message: The value at 'foo' cannot be null or empty to perform the test operation.

According to RFC6902 section 4.6, I believe it is incorrect to disallow values to be tested in this case.

To Reproduce

// Object with empty string property foo
dynamic myObject = new ExpandoObject();
myObject.foo = "";

// Create patch document with test operation
var doc = new JsonPatchDocument();
doc.Test("foo", "");

doc.ApplyTo(myObject); // <-- throws JsonPatchException

Exceptions (if any)

 Microsoft.AspNetCore.JsonPatch.Exceptions.JsonPatchException : The value at 'foo' cannot be null or empty to perform the test operation.

<.cctor>b__1_0(JsonPatchError error)
    ObjectAdapter.Test(Operation operation, Object objectToApplyTo)
    Operation.Apply(Object objectToApplyTo, IObjectAdapter adapter)
    JsonPatchDocument.ApplyTo(Object objectToApplyTo, IObjectAdapter adapter)
    JsonPatchDocument.ApplyTo(Object objectToApplyTo)
    UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)

Throw location: /src/Microsoft.AspNetCore.JsonPatch/Internal/DictionaryAdapterOfTU.cs

Further technical details

  • ASP.NET Core version 3.1
  • Microsoft.AspNetCore.JsonPatch 3.1.8
$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.401
 Commit:    5b6f5e5005

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support):
  Version: 3.1.7
  Commit:  fcfdef8d6b

.NET Core SDKs installed:
  3.1.200 [C:\Program Files\dotnet\sdk]
  3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]       
  Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]        
  Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]       
  Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]        
  Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]        
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]        
  Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
@henriksen
Copy link
Contributor

Same result on .NET 5

> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 20, 2020
@mkArtakMSFT mkArtakMSFT added this to the Next sprint planning milestone Nov 20, 2020
@ghost
Copy link

ghost commented Nov 20, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@ghost
Copy link

ghost commented Feb 18, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@captainsafia captainsafia added affected-few This issue impacts only small number of customers bug This issue describes a behavior which is not expected - a bug. severity-blocking This label is used by an internal tool labels Mar 15, 2021 — with ASP.NET Core Issue Ranking
@TanayParikh TanayParikh modified the milestones: Backlog, .NET 7 Planning Oct 19, 2021
@TanayParikh
Copy link
Contributor

Thanks, closing as duplicate of #25942

@TanayParikh TanayParikh added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Oct 19, 2021
@ghost ghost added the Status: Resolved label Oct 19, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 19, 2021
@amcasey amcasey added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-json-patch ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate severity-blocking This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

7 participants