Repository: dotnet/runtime
File: src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs (C#)

Code before:
            status = Base64.DecodeFromUtf8(base64Data, output, out bytesConsumed, out bytesWritten, isFinalBlock: true);
            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(base64Data.Length, bytesConsumed);
            Assert.True(bytesWritten > 0, "Should have decoded data");
        }

        [Theory]
        [InlineData("AAAA AA\r\nA=")]               // Just base64 start, then whitespace-split final quantum
        [InlineData("AA AA AAAA AA\r\nA=")]         // Previous blocks with spaces, then whitespace-split final quantum
        public void DecodingWithSpacesBeforeWhiteSpaceSplitFinalQuantum(string base64String)
        {
            // Test cases where previous blocks already contain spaces
            ReadOnlySpan<byte> base64Data = Encoding.ASCII.GetBytes(base64String);
            var output = new byte[100]; // Use larger buffer to avoid #123222

            // First call with isFinalBlock=false
            OperationStatus status = Base64.DecodeFromUtf8(base64Data, output, out int bytesConsumed, out int bytesWritten, isFinalBlock: false);
            
            // Verify we can complete decoding by retrying with the FULL input and isFinalBlock=true
            Array.Clear(output, 0, output.Length);
            status = Base64.DecodeFromUtf8(base64Data, output, out bytesConsumed, out bytesWritten, isFinalBlock: true);
            Assert.Equal(OperationStatus.Done, status);
            Assert.Equal(base64Data.Length, bytesConsumed);
            Assert.True(bytesWritten > 0, "Should have decoded data");
        }

    }
}


Review comment (suggestion):
```suggestion
```
The test right above already tests this

Code after:
            Assert.Equal(OperationStatus.Done, status3);
            Assert.Equal(input.Length, consumed3);
            Assert.Equal(3, written3);

            // Also test with larger embedded whitespace
            byte[] input2 = Encoding.UTF8.GetBytes("z  A  w  w");
            byte[] destination2 = new byte[3];
            OperationStatus status2 = Base64.DecodeFromUtf8(input2, destination2, out int consumed2, out int written2);
            Assert.Equal(OperationStatus.Done, status2);
            Assert.Equal(input2.Length, consumed2);
            Assert.Equal(3, written2);
        }

        [Fact]
        public void DecodingWithEmbeddedWhiteSpaceIntoSmallDestination_ActualDestinationTooSmall()
        {
            // Tests DecodeWithWhiteSpaceBlockwiseWrapper path with actual destination too small.
            // Input "A Q I D B A = =" (embedded whitespace) decodes to 4 bytes.
            byte[] input = Encoding.UTF8.GetBytes("A Q I D B A = =");

            byte[] destination1 = new byte[1];
            OperationStatus status1 = Base64.DecodeFromUtf8(input, destination1, out _, out _);
            Assert.Equal(OperationStatus.DestinationTooSmall, status1);

            // With destination of 4 bytes, this should succeed.
            byte[] destination4 = new byte[4];
            OperationStatus status4 = Base64.DecodeFromUtf8(input, destination4, out int consumed4, out int written4);
            Assert.Equal(OperationStatus.Done, status4);
            Assert.Equal(input.Length, consumed4);
            Assert.Equal(4, written4);
            Assert.Equal(new byte[] { 1, 2, 3, 4 }, destination4);
        }

        [Theory]
        [InlineData("AQ\r\nQ=")]
        [InlineData("AQ\r\nQ=\r\n")]
        [InlineData("AQ Q=")]
        [InlineData("AQ\tQ=")]
        public void DecodingWithWhiteSpaceSplitFinalQuantumAndIsFinalBlockFalse(string base64String)
        {
            // When a final quantum (containing padding) is split by whitespace and isFinalBlock=false,
            // the decoder should not consume any bytes, allowing the caller to retry with isFinalBlock=true
            ReadOnlySpan<byte> base64Data = Encoding.ASCII.GetBytes(base64String);
            var output = new byte[10];

            // First call with isFinalBlock=false should consume 0 bytes
            OperationStatus status = Base64.DecodeFromUtf8(base64Data, output, out int bytesConsumed, out int bytesWritten, isFinalBlock: false);
            Assert.Equal(0, bytesConsumed);
            Assert.Equal(0, bytesWritten);
            Assert.Equal(OperationStatus.InvalidData, status);