Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix IRI domain name parsing for [80, 9F] chars
  • Loading branch information
MihaZupan committed Nov 22, 2022
commit 87c7f61249a5f80516d2a4a1e87deddd9ab763c4
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal static class DomainNameHelper
private static readonly IndexOfAnyValues<char> s_iriInvalidAsciiChars = IndexOfAnyValues.Create(
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F" +
"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F" +
" !\"#$%&'()*+,/:;<=>?@[\\]^`{|}~");
" !\"#$%&'()*+,/:;<=>?@[\\]^`{|}~\u007F");

private static readonly IndexOfAnyValues<char> s_asciiLetterUpperOrColonChars =
IndexOfAnyValues.Create("ABCDEFGHIJKLMNOPQRSTUVWXYZ:");
Expand Down Expand Up @@ -153,6 +153,13 @@ public static bool IsValid(ReadOnlySpan<char> hostname, bool iri, bool notImplic
ReadOnlySpan<char> label = hostname.Slice(0, labelLength);
if (!IsAscii(label))
{
// s_iriInvalidAsciiChars confirmed everything in [0, 7F] range.
// Chars in [80, A0) range are also invalid, check for them now.
if (hostname.IndexOfAnyInRange('\u0080', '\u009F') >= 0)
{
return false;
}

// Account for the ACE prefix ("xn--")
labelLength += 4;

Expand Down