From 5848058e6327ed5cc139192d93ac8854f5d28844 Mon Sep 17 00:00:00 2001 From: Heath Baron-Morgan Date: Thu, 9 Mar 2023 22:13:40 -0800 Subject: [PATCH] Adress PR feedback: Add test to demonstrate extra whitespace is counted --- .../tests/Base64/Base64DecoderUnitTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs b/src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs index c08b9569c25ecd..448d6ccd4ed902 100644 --- a/src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs +++ b/src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs @@ -730,5 +730,38 @@ public void DecodingInPlaceWithOnlyCharsToBeIgnored(string utf8WithCharsToBeIgno Assert.Equal(OperationStatus.Done, result); Assert.Equal(0, bytesWritten); } + + [Theory] + [InlineData("AQ==", 4, 1)] + [InlineData("AQ== ", 5, 1)] + [InlineData("AQ== ", 6, 1)] + [InlineData("AQ== ", 7, 1)] + [InlineData("AQ== ", 8, 1)] + [InlineData("AQ== ", 9, 1)] + [InlineData("AQ==\n", 5, 1)] + [InlineData("AQ==\n\n", 6, 1)] + [InlineData("AQ==\n\n\n", 7, 1)] + [InlineData("AQ==\n\n\n\n", 8, 1)] + [InlineData("AQ==\n\n\n\n\n", 9, 1)] + [InlineData("AQ==\t", 5, 1)] + [InlineData("AQ==\t\t", 6, 1)] + [InlineData("AQ==\t\t\t", 7, 1)] + [InlineData("AQ==\t\t\t\t", 8, 1)] + [InlineData("AQ==\t\t\t\t\t", 9, 1)] + [InlineData("AQ==\r", 5, 1)] + [InlineData("AQ==\r\r", 6, 1)] + [InlineData("AQ==\r\r\r", 7, 1)] + [InlineData("AQ==\r\r\r\r", 8, 1)] + [InlineData("AQ==\r\r\r\r\r", 9, 1)] + public void BasicDecodingWithExtraWhitespaceShouldBeCountedInConsumedBytes(string inputString, int expectedConsumed, int expectedWritten) + { + Span source = Encoding.ASCII.GetBytes(inputString); + Span decodedBytes = new byte[Base64.GetMaxDecodedFromUtf8Length(source.Length)]; + + Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(source, decodedBytes, out int consumed, out int decodedByteCount)); + Assert.Equal(expectedConsumed, consumed); + Assert.Equal(expectedWritten, decodedByteCount); + Assert.True(Base64TestHelper.VerifyDecodingCorrectness(expectedConsumed, expectedWritten, source, decodedBytes)); + } } }