Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/libraries/System.Private.Uri/src/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,10 @@ private unsafe ParsingError PrivateParseMinimal()
if (newHost is not null)
{
_string = newHost;
// newHost contains everything from the start through the end of the authority
// with bidi characters removed. idx should point to the position right after
// the authority in the new string, which is simply newHost.Length.
idx = newHost.Length;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Private.Uri/tests/FunctionalTests/UriTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,5 +1001,21 @@ static void Test(string uriString)
Assert.Throws<OutOfMemoryException>(() => uri.AbsoluteUri);
}
}

[Theory]
[InlineData("/\\//")]
[InlineData("\\/\u200e")]
[InlineData("/\\\\-\u0100\r")]
[InlineData("\\\\\\\\\\")]
[InlineData("\\\\\u200E")]
[InlineData("\\\\\u200E:1234")]
[InlineData("\\\\\u200E//")]
[InlineData("\\\\\u200E//ab")]
public static void InvalidUriWithBidiControlCharacters_ThrowsUriFormatException(string uriString)
{
// These URIs should throw UriFormatException, not IndexOutOfRangeException
// Issue: https://github.com/dotnet/runtime/issues/18640
Assert.Throws<UriFormatException>(() => new Uri(uriString, UriKind.Absolute));
}
}
}
Loading