Skip to content

Commit 67e2eca

Browse files
MaximysMaksim Golev
andauthored
Fix invalid user info processing (#91106)
* fix(#88265): Fix invalid user info processing. * fix(#88265): Fix failed test. * feature(#88265): Adding additional test case. * fix(#88265): Fix invalid code style. --------- Co-authored-by: Maksim Golev <mgolev@htc-cs.ru>
1 parent c7d36b4 commit 67e2eca

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/libraries/System.Private.Uri/src/System/UriExt.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,11 @@ public bool IsBaseOf(Uri uri)
866866

867867
internal bool IsBaseOfHelper(Uri uriLink)
868868
{
869+
const UriComponents ComponentsToCompare =
870+
UriComponents.AbsoluteUri
871+
& ~UriComponents.Fragment
872+
& ~UriComponents.UserInfo;
873+
869874
if (!IsAbsoluteUri || UserDrivenParsing)
870875
return false;
871876

@@ -892,8 +897,8 @@ internal bool IsBaseOfHelper(Uri uriLink)
892897
return false;
893898

894899
// Canonicalize and test for substring match up to the last path slash
895-
string self = GetParts(UriComponents.AbsoluteUri & ~UriComponents.Fragment, UriFormat.SafeUnescaped);
896-
string other = uriLink.GetParts(UriComponents.AbsoluteUri & ~UriComponents.Fragment, UriFormat.SafeUnescaped);
900+
string self = GetParts(ComponentsToCompare, UriFormat.SafeUnescaped);
901+
string other = uriLink.GetParts(ComponentsToCompare, UriFormat.SafeUnescaped);
897902

898903
unsafe
899904
{

src/libraries/System.Private.Uri/tests/FunctionalTests/UriParserTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,9 @@ public static void IsBaseOf()
272272
Assert.False(parser.IsBaseOf(u, http), "http-4a");
273273
Assert.True(parser.IsBaseOf(http, u), "http-4b");
274274

275-
// docs says the UserInfo isn't evaluated, but...
276275
u = new Uri("http://username:password@www.mono-project.com/Main_Page");
277-
Assert.False(parser.IsBaseOf(u, http), "http-5a");
278-
Assert.False(parser.IsBaseOf(http, u), "http-5b");
276+
Assert.True(parser.IsBaseOf(u, http), "http-5a");
277+
Assert.True(parser.IsBaseOf(http, u), "http-5b");
279278

280279
// scheme case sensitive ? no
281280
u = new Uri("HTTP://www.mono-project.com/Main_Page");

src/libraries/System.Runtime/tests/System/Uri.MethodsTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ public static IEnumerable<object[]> IsBaseOfTestData()
196196
yield return new object[] { new Uri("file://C:/path/path/file"), new Uri("file://D:/path/path/path"), false };
197197
yield return new object[] { new Uri("file://C:/path/path/file"), new Uri("http://host/path/path/file"), false };
198198
yield return new object[] { new Uri("file://C:/path/path/file"), new Uri("path/path/file", UriKind.Relative), true };
199+
200+
yield return new object[] { new Uri("https://user@domain.com"), new Uri("https://domain.com"), true };
201+
yield return new object[] { new Uri("https://user@domain.com"), new Uri("http://domain.com"), false };
202+
yield return new object[] { new Uri("https://user1@domain.com"), new Uri("https://user2@domain.com"), true };
203+
yield return new object[] { new Uri("https://domain.com"), new Uri("https://user@domain.com"), true };
199204
}
200205

201206
[Theory]

0 commit comments

Comments
 (0)