Skip to content

Commit c94a149

Browse files
Prevent DataSourceLoadOptionsParser from System.InvalidOperationException on parsing binary filter with value null (#620)
1 parent d259461 commit c94a149

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ public void MustNotParseDates() {
5959
Assert.IsType<string>(opts.Filter[1]);
6060
}
6161

62+
[Fact]
63+
public void MustParseNull() {
64+
var opts = new SampleLoadOptions();
65+
66+
DataSourceLoadOptionsParser.Parse(opts, key => {
67+
if(key == DataSourceLoadOptionsParser.KEY_FILTER)
68+
return @"[ ""fieldName"", ""="", null ]";
69+
return null;
70+
});
71+
72+
Assert.Equal(new[] { "fieldName", "=", null }, opts.Filter.Cast<string>());
73+
}
74+
6275
[Fact]
6376
public void MustParseNumericAsString() {
6477
var opts = new SampleLoadOptions();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections;
2+
using System.Text.Json;
3+
using Xunit;
4+
5+
namespace DevExtreme.AspNet.Data.Tests {
6+
7+
public class DeserializeTests {
8+
static readonly JsonSerializerOptions TESTS_DEFAULT_SERIALIZER_OPTIONS = new JsonSerializerOptions(JsonSerializerDefaults.Web) {
9+
Converters = { new ListConverter() }
10+
};
11+
12+
[Theory]
13+
[InlineData(@"[""fieldName"",""="",null]")]
14+
[InlineData(@"[[""fieldName1"",""="",""""],""and"",[""fieldName2"",""="",null]]")]
15+
public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
16+
var deserializedList = JsonSerializer.Deserialize<IList>(rawJsonCriteria, TESTS_DEFAULT_SERIALIZER_OPTIONS);
17+
Assert.Equal(3, deserializedList.Count);
18+
}
19+
}
20+
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if NEWTONSOFT_TESTS
2+
using System.Collections;
3+
using Newtonsoft.Json;
4+
using Xunit;
5+
6+
namespace DevExtreme.AspNet.Data.Tests {
7+
8+
public class DeserializeTestsEx {
9+
[Theory]
10+
[InlineData(@"[""fieldName"",""="",null]")]
11+
[InlineData(@"[[""fieldName1"",""="",""""],""and"",[""fieldName2"",""="",null]]")]
12+
public void FilterOperandValueCanBeNull(string rawJsonCriteria) {
13+
var deserializedList = JsonConvert.DeserializeObject<IList>(rawJsonCriteria);
14+
Assert.Equal(3, deserializedList.Count);
15+
}
16+
}
17+
18+
}
19+
#endif

net/DevExtreme.AspNet.Data/Compatibility.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public static IList UnwrapList(IList deserializedList) {
1818
}
1919

2020
static object UnwrapJsonElement(object deserializeObject) {
21+
if(deserializeObject == null)
22+
return null;
23+
2124
if(!(deserializeObject is JsonElement jsonElement))
2225
throw new InvalidOperationException();
2326

0 commit comments

Comments
 (0)