Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/libraries/System.Private.Uri/src/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,7 @@ private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs)
Debug.Assert(_info != null && (_flags & Flags.MinimalUriInfoSet) != 0);

// Which Uri parts are not escaped canonically ?
// Notice that public UriComponents and private Uri.Flags must me in Sync so below code can work
// Notice that public UriComponents and private Uri.Flags must be in Sync so below code can work
//
ushort nonCanonical = unchecked((ushort)((ushort)_flags & (ushort)Flags.CannotDisplayCanonical));

Expand Down Expand Up @@ -3297,6 +3297,10 @@ private unsafe void ParseRemaining()
{
_string = _syntax.SchemeName + SchemeDelimiter;
}

_info.Offset.Scheme = 0;
_info.Offset.User = (ushort)_string.Length;
_info.Offset.Host = (ushort)_string.Length;
}

_info.Offset.Path = (ushort)_string.Length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Xunit;

namespace System.PrivateUri.Tests
Expand Down Expand Up @@ -82,5 +83,43 @@ public void GetComponents_UnknownScheme_LocalHostAndPort_Success()
Assert.Equal("127.0.0.1", testUri.Host);
Assert.Equal(23714, testUri.Port);
}

public static IEnumerable<object[]> NonAsciiFile_TestData
{
get
{
yield return new object[] { "file:///\u00FC", "file:///%C3%BC" };
yield return new object[] { " file:///\u00FC", "file:///%C3%BC" };

yield return new object[] { "file://C:/\u00FC", "file:///C:/%C3%BC" };
yield return new object[] { "file:///C:/\u00FC", "file:///C:/%C3%BC" };
yield return new object[] { " file://C:/\u00FC", "file:///C:/%C3%BC" };
yield return new object[] { " file:///C:/\u00FC", "file:///C:/%C3%BC" };

yield return new object[] { "C:/\u00FC", "file:///C:/%C3%BC" };
yield return new object[] { " C:/\u00FC", "file:///C:/%C3%BC" };

if (PlatformDetection.IsNotWindows)
{
yield return new object[] { "/\u00FC", "file:///%C3%BC" };
yield return new object[] { " /\u00FC", "file:///%C3%BC" };
}
}
}

[Theory]
[MemberData(nameof(NonAsciiFile_TestData))]
public static void NonAsciiFile(string uriString, string absoluteUri)
{
Uri testUri = new Uri(uriString);

Assert.Equal("file", testUri.GetComponents(UriComponents.Scheme, UriFormat.UriEscaped));
Assert.Equal("file://", testUri.GetComponents(UriComponents.Scheme | UriComponents.Host, UriFormat.UriEscaped));
Assert.Equal("file://", testUri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped));
Assert.Equal("", testUri.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped));
Assert.Equal("", testUri.GetComponents(UriComponents.UserInfo | UriComponents.Host, UriFormat.UriEscaped));
Assert.Equal("", testUri.GetComponents(UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped));
Assert.Equal(absoluteUri, testUri.GetComponents(UriComponents.AbsoluteUri, UriFormat.UriEscaped));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -813,16 +813,18 @@ public static IEnumerable<object[]> FilePathHandlesNonAscii_TestData()
// Unix absolute file path
yield return new object[] { "/\u00FCri/", "file:///\u00FCri/", "/%C3%BCri/", "file:///%C3%BCri/", "/\u00FCri/" };
yield return new object[] { "/a/b\uD83D\uDE1F/Foo.cs", "file:///a/b\uD83D\uDE1F/Foo.cs", "/a/b%F0%9F%98%9F/Foo.cs", "file:///a/b%F0%9F%98%9F/Foo.cs", "/a/b\uD83D\uDE1F/Foo.cs" };
yield return new object[] { "\t/\u00FCri/", "file:///\u00FCri/", "/%C3%BCri/", "file:///%C3%BCri/", "/\u00FCri/" };
}

// Absolute fie path
// Absolute file path
yield return new object[] { "file:///\u00FCri/", "file:///\u00FCri/", "/%C3%BCri/", "file:///%C3%BCri/", "/\u00FCri/" };
yield return new object[] { "file:///a/b\uD83D\uDE1F/Foo.cs", "file:///a/b\uD83D\uDE1F/Foo.cs", "/a/b%F0%9F%98%9F/Foo.cs", "file:///a/b%F0%9F%98%9F/Foo.cs", "/a/b\uD83D\uDE1F/Foo.cs" };

// DOS
yield return new object[] { "file://C:/\u00FCri/", "file:///C:/\u00FCri/", "C:/%C3%BCri/", "file:///C:/%C3%BCri/", "C:\\\u00FCri\\" };
yield return new object[] { "file:///C:/\u00FCri/", "file:///C:/\u00FCri/", "C:/%C3%BCri/", "file:///C:/%C3%BCri/", "C:\\\u00FCri\\" };
yield return new object[] { "C:/\u00FCri/", "file:///C:/\u00FCri/", "C:/%C3%BCri/", "file:///C:/%C3%BCri/", "C:\\\u00FCri\\" };
yield return new object[] { "\tC:/\u00FCri/", "file:///C:/\u00FCri/", "C:/%C3%BCri/", "file:///C:/%C3%BCri/", "C:\\\u00FCri\\" };

// UNC
yield return new object[] { "\\\\\u00FCri/", "file://\u00FCri/", "/", "file://\u00FCri/", "\\\\\u00FCri\\" };
Expand Down
Loading