Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Revert "Fix Uri.Host for IPv6 Link-local address (#29829)" #30062

Merged
merged 1 commit into from
Jun 4, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ private void SetUrl()
Uri requestUri = _requestMessage.RequestUri;

long scopeId;
bool isLinkLocal = false;
if ((isLinkLocal = IsLinkLocal(requestUri, out scopeId)))
if (IsLinkLocal(requestUri, out scopeId))
{
// Uri.AbsoluteUri doesn't include the ScopeId/ZoneID, so if it is link-local,
// we separately pass the scope to libcurl.
Expand All @@ -273,11 +272,10 @@ private void SetUrl()
}

EventSourceTrace("Url: {0}", requestUri);
int scopeIdIndex = 0;
string idnHost = requestUri.IdnHost;
string url = requestUri.Host == idnHost ?
requestUri.AbsoluteUri :
new UriBuilder(requestUri){ Host = isLinkLocal && (scopeIdIndex = idnHost.IndexOf("%")) != -1 ? idnHost.Substring(0, scopeIdIndex) : idnHost}.Uri.AbsoluteUri;
string url = requestUri.Host == idnHost ?
requestUri.AbsoluteUri :
new UriBuilder(requestUri) { Host = idnHost }.Uri.AbsoluteUri;

SetCurlOption(CURLoption.CURLOPT_URL, url);
SetCurlOption(CURLoption.CURLOPT_PROTOCOLS, (long)(CurlProtocols.CURLPROTO_HTTP | CurlProtocols.CURLPROTO_HTTPS));
Expand Down
5 changes: 2 additions & 3 deletions src/System.Private.Uri/src/System/IPv6AddressHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class IPv6AddressHelper

// methods

internal static string ParseCanonicalName(string str, int start, ref bool isLoopback, ref bool linkLocalAddress, ref string scopeId)
internal static string ParseCanonicalName(string str, int start, ref bool isLoopback, ref string scopeId)
{
unsafe
{
Expand All @@ -31,8 +31,7 @@ internal static string ParseCanonicalName(string str, int start, ref bool isLoop
((long*)numbers)[0] = 0L;
((long*)numbers)[1] = 0L;
isLoopback = Parse(str, numbers, start, ref scopeId);
linkLocalAddress = numbers[0] == 0xfe80;
return "[" + CreateCanonicalName(numbers) + (linkLocalAddress ? scopeId : "") + "]";
return '[' + CreateCanonicalName(numbers) + ']';
}
}

Expand Down
14 changes: 2 additions & 12 deletions src/System.Private.Uri/src/System/Uri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ private enum Flags : ulong
FragmentIriCanonical = 0x40000000000,
IriCanonical = 0x78000000000,
UnixPath = 0x100000000000,
IPv6LinkLocalAddress = 0x200000000000
}

private Flags _flags;
Expand Down Expand Up @@ -1194,9 +1193,7 @@ public string DnsSafeHost
if (HostType == Flags.IPv6HostType)
{
ret = ret.Substring(1, ret.Length - 2);

//To avoid duplicated ScopeId on Ipv6 local link address
if ((object)_info.ScopeId != null && (_flags & Flags.IPv6LinkLocalAddress) == 0)
if ((object)_info.ScopeId != null)
{
ret += _info.ScopeId;
}
Expand Down Expand Up @@ -2568,7 +2565,6 @@ private unsafe void CreateHostString()
private static string CreateHostStringHelper(string str, ushort idx, ushort end, ref Flags flags, ref string scopeId)
{
bool loopback = false;
bool linkLocalAddress = false;
string host;
switch (flags & Flags.HostTypeMask)
{
Expand All @@ -2578,7 +2574,7 @@ private static string CreateHostStringHelper(string str, ushort idx, ushort end,

case Flags.IPv6HostType:
// The helper will return [...] string that is not suited for Dns.Resolve()
host = IPv6AddressHelper.ParseCanonicalName(str, idx, ref loopback, ref linkLocalAddress, ref scopeId);
host = IPv6AddressHelper.ParseCanonicalName(str, idx, ref loopback, ref scopeId);
break;

case Flags.IPv4HostType:
Expand Down Expand Up @@ -2620,12 +2616,6 @@ private static string CreateHostStringHelper(string str, ushort idx, ushort end,
{
flags |= Flags.LoopbackHost;
}

if (linkLocalAddress)
{
flags |= Flags.IPv6LinkLocalAddress;
}

return host;
}

Expand Down
15 changes: 0 additions & 15 deletions src/System.Private.Uri/tests/FunctionalTests/IdnDnsSafeHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ public void IdnDnsSafeHost_IPv6Host_ScopeIdButNoBrackets()
Assert.Equal("[::1]", test.Host);
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public void IdnDnsSafeHost_IPv6HostLinkLocalAddress_ScopeIdCorrectlyFormatted()
{
const string ScopedLiteralIpv6 = "fe80::e077:c9a3:eeba:b8e9%18";

string scopedLiteralIpv6Brackets = "[" + ScopedLiteralIpv6 + "]";
string literalIpV6Uri = "http://" + scopedLiteralIpv6Brackets;
Uri test = new Uri(literalIpV6Uri);

Assert.Equal(ScopedLiteralIpv6, test.DnsSafeHost);
Assert.Equal(ScopedLiteralIpv6, test.IdnHost);
Assert.Equal(scopedLiteralIpv6Brackets, test.Host);
}

[Fact]
public void IdnDnsSafeHost_MixedCase_ToLowerCase()
{
Expand Down
30 changes: 0 additions & 30 deletions src/System.Private.Uri/tests/FunctionalTests/UriIpHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,36 +234,6 @@ private void ParseBadIPv4Address(string badIpv4String)

#region IPv6

[Theory]
[InlineData("fe80::e077:c9a3:eeba:b8e9", "%18")]
[InlineData("Fe80::e077:c9a3:eeba:b8e9", "%18")]
[InlineData("fE80::e077:c9a3:eeba:b8e9", "%18")]
[InlineData("FE80::e077:c9a3:eeba:b8e9", "%18")]
[InlineData("FE80::e077:c9a3:eeba:b8e9", "%eth10")]
[InlineData("FE80::e077:c9a3:eeba:b8e9", "")]
[InlineData("FE80::e077:c9a3:eeba:b8e9", "%")]
[InlineData("fe80::e077:c9a3:eeba:b8e9", "%\u30AF\u20E7")]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
public void Host_IPv6LinkLocalAddress_HasScopeId(string address, string zoneIndex)
{
string scopedLiteralIpv6Brackets = "[" + address + zoneIndex + "]";
string literalIpV6Uri = "http://" + scopedLiteralIpv6Brackets;
var uri = new Uri(literalIpV6Uri);
Assert.Equal(scopedLiteralIpv6Brackets, uri.Host, ignoreCase: true);
}

[Fact]
public void Host_NonIPv6LinkLocalAddress_NoScopeId()
{
const string Address = "fe81::e077:c9a3:eeba:b8e9";
const string ZoneIndex = "%18";

string scopedLiteralIpv6Brackets = "[" + Address + ZoneIndex + "]";
string literalIpV6Uri = "http://" + scopedLiteralIpv6Brackets;
var uri = new Uri(literalIpV6Uri);
Assert.Equal("[" + Address + "]", uri.Host);
}

[Fact]
public void UriIPv6Host_CanonicalCollonHex_Success()
{
Expand Down