Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: Base64.DecodeFromUtf8{InPlace} ignore whitespace #35282

Closed
1 of 3 tasks
stephentoub opened this issue May 9, 2023 · 0 comments · Fixed by #35725
Closed
1 of 3 tasks

[Breaking change]: Base64.DecodeFromUtf8{InPlace} ignore whitespace #35282

stephentoub opened this issue May 9, 2023 · 0 comments · Fixed by #35725
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@stephentoub
Copy link
Member

stephentoub commented May 9, 2023

Description

The System.Convert.FromBase64String, System.Convert.FromBase64CharArray, and corresponding Try methods on System.Convert have long ignored some ASCII whitespace characters (' ', '\t', '\r', '\n'), allowing any amount of such whitespace to be in the input. However, when the System.Buffers.Text.Base64.DecodeFromUtf8 and System.Buffers.Text.Base64.DecodeFromUtf8InPlace methods were added, they did not ignore these whitespace characters and would instead fail to decode any input that included whitespace. This makes the behavior when using the UTF16-based APIs different from that using the UTF8-based APIs, and means that the Base64.DecodeFromUtf8 and Base64.DecodeFromUtf8InPlace methods couldn't roundtrip UTF-encoded base-64 encoded data produced by Convert.ToBase64String with the Base64FormattingOptions.InsertLineBreaks option. It also means that the new Base64.IsValid(ReadOnlySpan<char>) and Base64.IsValid(ReadOnlySpan<byte>) methods would either need to have behavior inconsistent with each other or with their corresponding methods for UTF16 and UTF8 data on Convert and Base64.

Version

.NET 8 Preview 5

Previous behavior

System.Buffers.Text.Base64.DecodeFromUtf8 and System.Buffers.Text.Base64.DecodeFromUtf8InPlace would fail to process input containing whitespace, returning OperationStatus.InvalidData if any whitespace was encountered.

New behavior

System.Buffers.Text.Base64.DecodeFromUtf8 and System.Buffers.Text.Base64.DecodeFromUtf8InPlace now ignore whitespace (specifically ' ', '\t', '\r', and '\n') in the input, matching the behavior of Convert.FromBase64String.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

The change was made so that:

  • the Base64 methods could decode a wider range of input data, including that produced by Convert.ToBase64String with the Base64FormattingOptions.InsertLineBreaks option as well as common formatting of data in configuration files and other real data sources.
  • the Base64 methods would be consistent with the corresponding decoding APIs on System.Convert.
  • the new Base64.IsValid APIs could be added in a manner where their behavior is consistent with each other and with the existing Convert and Base64 APIs.

Recommended action

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

Feature area

Core .NET libraries

Affected APIs

  • System.Buffers.Text.Base64.DecodeFromUtf8
  • System.Buffers.Text.Base64.DecodeFromUtf8InPlace

Associated WorkItem - 97023

@stephentoub stephentoub added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels May 9, 2023
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label May 9, 2023
@gewarren gewarren added 🏁 Release: .NET 8 Work items for the .NET 8 release and removed ⌚ Not Triaged Not triaged labels May 9, 2023
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Jun 2, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Jun 3, 2023
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Jun 8, 2023
@gewarren gewarren moved this from 🔖 Ready to 👀 In review in dotnet/docs June 2023 sprint Jun 8, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in dotnet/docs June 2023 sprint Jun 13, 2023
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in .NET 8.0 work items Jun 13, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 8 Work items for the .NET 8 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants