forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and optimize EscapeUnescapeIri (dotnet#32025)
* Remove byte[] allocation per encoded character * Remove dead code from EscapeUnescapeIri * Use int instead of IntPtr for stack buffer * Use sizeof(int) instead of 4 as const * Fix EscapeUnescapeIri for escaped surrogate pairs
- Loading branch information
Showing
3 changed files
with
71 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/libraries/System.Private.Uri/tests/FunctionalTests/EscapeUnescapeIriTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.PrivateUri.Tests | ||
{ | ||
public class EscapeUnescapeIriTests | ||
{ | ||
public static IEnumerable<object[]> ReplacesStandaloneSurrogatesWithReplacementChar() | ||
{ | ||
const string UrlEncodedReplacementChar = "%EF%BF%BD"; | ||
const string HighSurrogate = "\ud83f"; | ||
const string LowSurrogate = "\udffe"; | ||
|
||
yield return new object[] { "a", "a" }; | ||
yield return new object[] { HighSurrogate + LowSurrogate, "%F0%9F%BF%BE" }; | ||
yield return new object[] { HighSurrogate, UrlEncodedReplacementChar }; | ||
yield return new object[] { LowSurrogate, UrlEncodedReplacementChar }; | ||
yield return new object[] { LowSurrogate + HighSurrogate, UrlEncodedReplacementChar + UrlEncodedReplacementChar }; | ||
yield return new object[] { LowSurrogate + LowSurrogate, UrlEncodedReplacementChar + UrlEncodedReplacementChar }; | ||
yield return new object[] { HighSurrogate + HighSurrogate, UrlEncodedReplacementChar + UrlEncodedReplacementChar }; | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(ReplacesStandaloneSurrogatesWithReplacementChar))] | ||
public static void ReplacesStandaloneSurrogatesWithReplacementChar(string input, string expected) | ||
{ | ||
const string Prefix = "scheme:"; | ||
Uri uri = new Uri(Prefix + input); | ||
string actual = uri.AbsoluteUri.Substring(Prefix.Length); | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters