Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ public string JsonPath()
{
StringBuilder sb = new StringBuilder("$");

// If a continuation, always report back full stack.
int count = Math.Max(_count, _continuationCount);
// If a continuation, always report back full stack which does not use Current for the last frame.
int count = Math.Max(_count, _continuationCount + 1);

for (int i = 0; i < count - 1; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ public string PropertyPath()
{
StringBuilder sb = new StringBuilder("$");

// If a continuation, always report back full stack.
int count = Math.Max(_count, _continuationCount);
// If a continuation, always report back full stack which does not use Current for the last frame.
int count = Math.Max(_count, _continuationCount + 1);

for (int i = 0; i < count - 1; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,47 @@ public class ChildClass
public ChildClass[] Children { get; set; }
}

[Fact]
public async Task PathForChildListFails()
private const string PathForChildListFails_Json = @"{""Child"":{""MyIntArray"":[1, bad]}";

[Theory]
[MemberData(nameof(PathForChildDictionaryFails_TestData))]
public async Task PathForChildListFails(int bufferSize)
{
JsonException e = await Assert.ThrowsAsync<JsonException>(() => JsonSerializerWrapperForString.DeserializeWrapper<RootClass>(@"{""Child"":{""MyIntArray"":[1, bad]}"));
JsonSerializerOptions options = new() { DefaultBufferSize = bufferSize };
JsonException e = await Assert.ThrowsAsync<JsonException>(() => JsonSerializerWrapperForString.DeserializeWrapper<RootClass>(PathForChildListFails_Json, options));
Assert.Contains("$.Child.MyIntArray", e.Path);
}

[Fact]
public async Task PathForChildDictionaryFails()
public static IEnumerable<object[]> PathForChildListFails_TestData()
{
JsonException e = await Assert.ThrowsAsync<JsonException>(() => JsonSerializerWrapperForString.DeserializeWrapper<RootClass>(@"{""Child"":{""MyDictionary"":{""Key"": bad]"));
int maxBufferSize = PathForChildListFails_Json.Length * 2;
for (int i = 1; i <= maxBufferSize; i++)
{
yield return new object[] { i };
}
}

private const string PathForChildDictionaryFails_Json = @"{""Child"":{""MyDictionary"":{""Key"": bad]";

[Theory]
[MemberData(nameof(PathForChildDictionaryFails_TestData))]
public async Task PathForChildDictionaryFails(int bufferSize)
{
JsonSerializerOptions options = new() { DefaultBufferSize = bufferSize };
JsonException e = await Assert.ThrowsAsync<JsonException>(() => JsonSerializerWrapperForString.DeserializeWrapper<RootClass>(PathForChildDictionaryFails_Json, options));
Assert.Equal("$.Child.MyDictionary.Key", e.Path);
}

public static IEnumerable<object[]> PathForChildDictionaryFails_TestData()
{
int maxBufferSize = PathForChildDictionaryFails_Json.Length * 2;

for (int i = 1; i <= maxBufferSize; i++)
{
yield return new object[] { i };
}
}

[Fact]
public async Task PathForSpecialCharacterFails()
{
Expand Down