diff options
Diffstat (limited to 'src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs')
-rw-r--r-- | src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs index 8496254aaed..b08e8b758e9 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs @@ -233,6 +233,31 @@ namespace System.Text.Json.Serialization.Tests Assert.Equal(expectedFailure.Column, ex.BytePositionInLine); } + [Fact] + public static async Task BomHandlingRegressionTest() + { + byte[] utf8Bom = Encoding.UTF8.GetPreamble(); + byte[] json = """{ "Value" : "Hello" }"""u8.ToArray(); + + using var stream = new MemoryStream(); + stream.Write(utf8Bom, 0, utf8Bom.Length); + stream.Write(json, 0, json.Length); + stream.Position = 0; + + var options = new JsonSerializerOptions + { + DefaultBufferSize = 32 + }; + + Test result = await JsonSerializer.DeserializeAsync<Test>(stream, options); + Assert.Equal("Hello", result.Value); + } + + private class Test + { + public string Value { get; set; } + } + private class Chunk : ReadOnlySequenceSegment<byte> { public Chunk(string json, int firstSegmentLength) |