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

Differ fails when path contains a ' #22

Open
Fl0GUI opened this issue Dec 14, 2022 · 0 comments · May be fixed by #23
Open

Differ fails when path contains a ' #22

Fl0GUI opened this issue Dec 14, 2022 · 0 comments · May be fixed by #23

Comments

@Fl0GUI
Copy link

Fl0GUI commented Dec 14, 2022

An example:
from:

{
    "isn't": true
}

This is valid json.
to:

{
    "isn't": false
}

This is also valid json, but running the Differ gives:

> new JsonDiffer().Differ(from, to, false)
   Newtonsoft.Json.JsonReaderException : After parsing a value an unexpected character was encountered: t. Path 'path', line 1, position 33.
     at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json)
   at JsonDiffPatch.Operation.Parse(String json)
   at JsonDiffPatch.JsonDiffer.Build(String op, String path, String key, JToken value)
   at JsonDiffPatch.JsonDiffer.CalculatePatch(JToken left, JToken right, Boolean useIdToDetermineEquality, String path)+MoveNext()
   at JsonDiffPatch.JsonDiffer.CalculatePatch(JToken left, JToken right, Boolean useIdToDetermineEquality, String path)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at JsonDiffPatch.JsonDiffer.Diff(JToken from, JToken to, Boolean useIdPropertyToDetermineEquality)

I am pretty certain the error happens in

Operation.Parse("{ 'op' : '" + op + "' , path: '" + path + "', value: " +
(value == null ? "null" : value.ToString(Formatting.None)) + "}");
or
Operation.Parse("{ op : '" + op + "' , path : '" + Extend(path, key) + "' , value : " +
(value == null ? "null" : value.ToString(Formatting.None)) + "}");
.
This code creates { 'op' : 'replace' , path: '/isn't', value: true} which isn't valid json at all. The only reason it doesn't fail in other cases is that JObject.Parse is generous.

@Fl0GUI Fl0GUI linked a pull request Dec 19, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant