You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Several public methods (Uri.EscapeDataString, Uri.EscapeUriString) and a bunch of internal call sites rely on the internal EscapeString helper. This helper has several issues with it:
- It uses unsafe code.
- It unnecessarily requires and copies through a char[] to get to a string when a string is the required result.
- It has a lot of complexity around the handling of unicode.
This PR rewrites it to utilize Span, Rune, and other newer features in a way that enables it to be both safe and efficient. Most inputs ends up being faster, and for very long inputs, it's much, much faster. The use of ValueStringBuilder also results in less memory allocation, in some cases significantly.
The use of Rune also fixes two arguable bugs in the existing implementation around invalid Unicode sequences, which is why a couple tests were tweaked:
- Some but not all invalid unicode patterns result in replacement characters being used: a few invalid sequences (e.g. just a high surrogate) result in an exception. We should be standardized on using replacement characters for all such invalid sequences.
- Some patterns with invalid unicode patterns actually result in unnecessary encoding, e.g. `Uri.EscapeDataString("\uD800\uD800a")` results in `a` being encoded.
[Obsolete("The method has been deprecated. Please use GetComponents() or static EscapeUriString() to escape a Uri component or a string. https://go.microsoft.com/fwlink/?linkid=14202")]
5340
-
protected staticstring EscapeString(string? str)
5341
-
{
5342
-
// This method just does not make sense as protected
5343
-
// It should go public static asap
5344
-
5345
-
if(str ==null)
5346
-
{
5347
-
returnstring.Empty;
5348
-
}
5349
-
5350
-
int destStart =0;
5351
-
char[]? dest = UriHelper.EscapeString(str,0,str.Length,null,refdestStart,true, '?', '#', '%');
0 commit comments