Skip to content

Commit ae3926f

Browse files
committed
Fix JsonUtils.GetFailurePath for root arrays and empty values
1 parent 78922b6 commit ae3926f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Framework/Framework/Utils/SystemTextJsonUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public static string[] GetFailurePath(ReadOnlySpan<byte> data)
1818
// the "max depth exceeded" error
1919
var options = new JsonReaderOptions { MaxDepth = 196 };
2020
var reader = new Utf8JsonReader(data, false, new JsonReaderState(options));
21-
reader.AssertRead();
22-
if (reader.TokenType != JsonTokenType.StartObject) throw new Exception("wtf");
21+
if (!reader.Read())
22+
return [];
2323
return GetFailurePathInternal(ref reader) ?? throw new Exception("No error in specified JSON");
2424
}
2525

src/Tests/ViewModel/JsonUtilsTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,22 @@ public class JsonUtilsTests
8484
"items/0"
8585
)]
8686
[DataRow(
87-
$$"""
87+
"""
8888
{ "arr": [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1, 2], []]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]],
8989
"prop": 1
9090
""",
9191
"prop"
9292
)]
93+
[DataRow(
94+
"""
95+
[
96+
1, 2,
97+
{ "ok": true },
98+
{ "not_ok":
99+
""",
100+
"3/not_ok"
101+
)]
102+
[DataRow(" ", "")]
93103
public void GetInvalidJsonErrorPath(string json, string expectedPath)
94104
{
95105
var utf8 = StringUtils.Utf8.GetBytes(json);

0 commit comments

Comments
 (0)