BindUriHelper.UriToString is technically broken as it fails to truncate the uri
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
`UriToString` is technically broken (both in .NET Framework and .NET Core) as it is supposed to truncate for lengths over 2083 chars but it fails to do so due to a misunderstanding how `StringBuilder`'s capacity works from the original developer.
https://github.com/dotnet/wpf/blob/bdec3d515f52c55bc3a6431e71db97c88f868215/src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/BindUriHelper.cs#L67-L71
It is the same in .NET Framework: https://referencesource.microsoft.com/#PresentationFramework/src/Shared/MS/Utility/BindUriHelper.cs,60
### Expected behavior
The URI is trimmed on string conversion if it exceeds `MAX_URL_LENGTH`.
### Actual behavior
Unnecessary allocations are made and the string is not trimmed as intended.
### Next steps
- We should definitely fix the unnecessary allocations.
- However, should we change it to the intended behavior, or should we keep the current one?
Contributor guide
Assessment
This issue has not been assessed yet.