Skip to content

Commit

Permalink
new feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TrayanZapryanov committed Jun 12, 2024
1 parent 6961eff commit 82cdaf2
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ internal static void HtmlEncode(string? value, TextWriter output)
private static int IndexOfHtmlAttributeEncodingChars(string s) =>
s.AsSpan().IndexOfAny("<\"'&");

private static bool IsNonAsciiOrSpaceByte(byte b) => (uint)b - 0x20 - 1 >= 0x7F - 0x20 - 1;

internal static string JavaScriptStringEncode(string? value, bool addDoubleQuotes)
{
int i = value.AsSpan().IndexOfAny(s_invalidJavaScriptChars);
Expand Down Expand Up @@ -621,13 +619,12 @@ private static string UrlPathEncodeImpl(string value)
: value.AsSpan(i);

byte[] bytes = ArrayPool<byte>.Shared.Rent(Encoding.UTF8.GetMaxByteCount(toEncode.Length));
char[] chars = ArrayPool<char>.Shared.Rent(bytes.Length * 3);

int utf8Length = Encoding.UTF8.GetBytes(toEncode, bytes);
char[] chars = ArrayPool<char>.Shared.Rent(utf8Length * 3);
int charCount = 0;
foreach (byte b in bytes.AsSpan(0, utf8Length))
{
if (IsNonAsciiOrSpaceByte(b))
if (!char.IsBetween((char)b, (char)0x21, (char)0x7F))
{
chars[charCount++] = '%';
chars[charCount++] = HexConverter.ToCharLower(b >> 4);
Expand Down

0 comments on commit 82cdaf2

Please sign in to comment.