Base64.DecodeFromUtf8 methods ignore whitespace

The Convert.FromBase64String(String), Convert.FromBase64CharArray(Char[], Int32, Int32), and corresponding Try methods on System.Convert ignore the ASCII whitespace characters ' ', '\t', '\r', and '\n' and allow any amount of such whitespace to be in the input. However, when the Base64.DecodeFromUtf8(ReadOnlySpan<Byte>, Span<Byte>, Int32, Int32, Boolean) and Base64.DecodeFromUtf8InPlace(Span<Byte>, Int32) methods were added, they didn't ignore these whitespace characters and instead failed to decode any input that included whitespace. That made the behavior of the UTF16-based APIs different from that of the UTF8-based APIs. It also meant that:

With this change, the DecodeFromUtf8(ReadOnlySpan<Byte>, Span<Byte>, Int32, Int32, Boolean) and DecodeFromUtf8InPlace(Span<Byte>, Int32) methods now ignore whitespace in the input.

Previous behavior

Base64.DecodeFromUtf8(ReadOnlySpan<Byte>, Span<Byte>, Int32, Int32, Boolean) and Base64.DecodeFromUtf8InPlace(Span<Byte>, Int32) failed to process input that contained whitespace and returned OperationStatus.InvalidData if any whitespace was encountered.

New behavior

Base64.DecodeFromUtf8(ReadOnlySpan<Byte>, Span<Byte>, Int32, Int32, Boolean) and Base64.DecodeFromUtf8InPlace(Span<Byte>, Int32) now ignore whitespace (specifically ' ', '\t', '\r', and '\n') in the input, which matches the behavior of Convert.FromBase64String(String).

Version introduced

.NET 8 Preview 5

Type of breaking change

This change is a behavioral change.

Reason for change

The change was made so that:

If the new behavior is problematic for your code, you can call IndexOfAny(" \t\r\n"u8) to search the input for the whitespace that previously would have triggered an InvalidData result.

Affected APIs