Skip to content

Commit

Permalink
Prevent DataSourceLoadOptionsParser from System.InvalidOperationExcep…
Browse files Browse the repository at this point in the history
…tion on parsing binary filter with value json object (#631)
  • Loading branch information
mpreyskurantov authored Aug 27, 2024
1 parent 0af7be9 commit 61ac579
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ public void MustParseNull() {
Assert.Equal(new[] { "fieldName", "=", null }, opts.Filter.Cast<string>());
}

[Fact]
public void MustParseObject() {
var opts = new SampleLoadOptions();

DataSourceLoadOptionsParser.Parse(opts, key => {
if(key == DataSourceLoadOptionsParser.KEY_FILTER)
return @"[ ""fieldName1"", ""="", {""Value"":0} ]";
return null;
});

Assert.Equal(3, opts.Filter.Count);
Assert.Equal("{\"Value\":0}", opts.Filter[2].ToString());
}

[Fact]
public void MustParseNumericAsString() {
var opts = new SampleLoadOptions();
Expand Down
7 changes: 7 additions & 0 deletions net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
var deserializedList = JsonSerializer.Deserialize<IList>(rawJsonCriteria, TESTS_DEFAULT_SERIALIZER_OPTIONS);
Assert.Equal(3, deserializedList.Count);
}

[Fact]
public void FilterOperandValueCanBeObject() {
var deserializedList = JsonSerializer.Deserialize<IList>(@"[""fieldName1"",""="",{""Value"":0}]", TESTS_DEFAULT_SERIALIZER_OPTIONS);
Assert.Equal(3, deserializedList.Count);
Assert.Equal("{\"Value\":0}", deserializedList[2].ToString());
}
}

}
7 changes: 7 additions & 0 deletions net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
var deserializedList = JsonConvert.DeserializeObject<IList>(rawJsonCriteria);
Assert.Equal(3, deserializedList.Count);
}

[Fact]
public void FilterOperandValueCanBeObject() {
var deserializedList = JsonConvert.DeserializeObject<IList>(@"[""fieldName1"",""="",{""Value"":0}]");
Assert.Equal(3, deserializedList.Count);
Assert.Equal("{\r\n \"Value\": 0\r\n}", deserializedList[2].ToString());
}
}

}
Expand Down
2 changes: 2 additions & 0 deletions net/DevExtreme.AspNet.Data/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static object UnwrapJsonElement(object deserializeObject) {
if(jsonElement.TryGetDecimal(out var decimalValue))
return decimalValue;
throw new NotImplementedException();
case JsonValueKind.Object:
return jsonElement;
default:
throw new NotImplementedException();
}
Expand Down

0 comments on commit 61ac579

Please sign in to comment.