Skip to content

ReadOnlySpan<char> overload of Uri.UnescapeDataString #54828

Closed
@SteveSandersonMS

Description

@SteveSandersonMS

Background and Motivation

For context, this emerged in ASP.NET Core at dotnet/aspnetcore#33840 (comment)

Currently, Uri.UnescapeDataString both accepts and returns string. If the source data you're working with is a ReadOnlySpan<char>, then the caller is forced to allocate a string. This is especially inefficient if the caller only needs back a ReadOnlySpan<char>, since in most cases this seems like it should be achievable without any allocations (because the original argument could be returned directly if no transformation was required - see below).

Proposed API

namespace System
{
     public class Uri
     {
+        ReadOnlySpan<char> UnescapeDataString(ReadOnlySpan<char> stringToUnescape) { ... }
     }
}

Of course, if the input data contains escaped characters, then the implementation will need to allocate in order to provide a return value. However the existing logic within string UnescapeDataString(string) recognizes the extremely common case where the input string does not contain escaped characters and knows to return the original string directly. Similarly, the new ReadOnlySpan<char> overload could return the original argument value in this case.

Usage Examples

var unescapedValue = Uri.UnescapeDataString(someCharSpanFromAUri);

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Net

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions