Skip to content

Commit 61ac579

Browse files
Prevent DataSourceLoadOptionsParser from System.InvalidOperationException on parsing binary filter with value json object (#631)
1 parent 0af7be9 commit 61ac579

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

net/DevExtreme.AspNet.Data.Tests/DataSourceLoadOptionsParserTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ public void MustParseNull() {
7272
Assert.Equal(new[] { "fieldName", "=", null }, opts.Filter.Cast<string>());
7373
}
7474

75+
[Fact]
76+
public void MustParseObject() {
77+
var opts = new SampleLoadOptions();
78+
79+
DataSourceLoadOptionsParser.Parse(opts, key => {
80+
if(key == DataSourceLoadOptionsParser.KEY_FILTER)
81+
return @"[ ""fieldName1"", ""="", {""Value"":0} ]";
82+
return null;
83+
});
84+
85+
Assert.Equal(3, opts.Filter.Count);
86+
Assert.Equal("{\"Value\":0}", opts.Filter[2].ToString());
87+
}
88+
7589
[Fact]
7690
public void MustParseNumericAsString() {
7791
var opts = new SampleLoadOptions();

net/DevExtreme.AspNet.Data.Tests/DeserializeTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
1616
var deserializedList = JsonSerializer.Deserialize<IList>(rawJsonCriteria, TESTS_DEFAULT_SERIALIZER_OPTIONS);
1717
Assert.Equal(3, deserializedList.Count);
1818
}
19+
20+
[Fact]
21+
public void FilterOperandValueCanBeObject() {
22+
var deserializedList = JsonSerializer.Deserialize<IList>(@"[""fieldName1"",""="",{""Value"":0}]", TESTS_DEFAULT_SERIALIZER_OPTIONS);
23+
Assert.Equal(3, deserializedList.Count);
24+
Assert.Equal("{\"Value\":0}", deserializedList[2].ToString());
25+
}
1926
}
2027

2128
}

net/DevExtreme.AspNet.Data.Tests/DeserializeTestsEx.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
1313
var deserializedList = JsonConvert.DeserializeObject<IList>(rawJsonCriteria);
1414
Assert.Equal(3, deserializedList.Count);
1515
}
16+
17+
[Fact]
18+
public void FilterOperandValueCanBeObject() {
19+
var deserializedList = JsonConvert.DeserializeObject<IList>(@"[""fieldName1"",""="",{""Value"":0}]");
20+
Assert.Equal(3, deserializedList.Count);
21+
Assert.Equal("{\r\n \"Value\": 0\r\n}", deserializedList[2].ToString());
22+
}
1623
}
1724

1825
}

net/DevExtreme.AspNet.Data/Compatibility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static object UnwrapJsonElement(object deserializeObject) {
4343
if(jsonElement.TryGetDecimal(out var decimalValue))
4444
return decimalValue;
4545
throw new NotImplementedException();
46+
case JsonValueKind.Object:
47+
return jsonElement;
4648
default:
4749
throw new NotImplementedException();
4850
}

0 commit comments

Comments
 (0)