Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -1,3 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.CodeAnalysis;
// TODO: Remove this once https://github.com/dotnet/corefx/issues/13107 is fixed

View File

@@ -5,6 +5,7 @@
<ProjectGuid>{4AC5343E-6E31-4BA5-A795-0493AE7E9008}</ProjectGuid>
<AssemblyName>System.Private.Uri</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ILLinkClearInitLocals>true</ILLinkClearInitLocals>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
@@ -57,4 +58,4 @@
<ReferenceFromRuntime Include="System.Private.CoreLib" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@@ -3,16 +3,15 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Runtime.CompilerServices;
namespace System
{
// The class designed as to keep working set of Uri class as minimal.
// The idea is to stay with static helper methods and strings
internal class DomainNameHelper
internal static class DomainNameHelper
{
private DomainNameHelper()
{
}
private static readonly IdnMapping s_idnMapping = new IdnMapping();
internal const string Localhost = "localhost";
internal const string Loopback = "loopback";
@@ -76,10 +75,13 @@ namespace System
{
char ch = *newPos;
if (ch > 0x7f) return false; // not ascii
if (ch == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
if (ch < 'a') // Optimize for lower-case letters, which make up the majority of most Uris, and which are all greater than symbols checked for below
{
end = newPos;
break;
if (ch == '/' || ch == '\\' || (notImplicitFile && (ch == ':' || ch == '?' || ch == '#')))
{
end = newPos;
break;
}
}
}
@@ -272,8 +274,7 @@ namespace System
// check ace validity
try
{
IdnMapping map = new IdnMapping();
map.GetUnicode(new string(strippedHostPtr, curPos, newPos - curPos));
s_idnMapping.GetUnicode(strippedHost, curPos, newPos - curPos);
atLeastOneValidIdn = true;
break;
}
@@ -328,18 +329,15 @@ namespace System
}
else
{
IdnMapping map = new IdnMapping();
string asciiForm;
bidiStrippedHost = UriHelper.StripBidiControlCharacter(hostname, start, end - start);
try
{
asciiForm = map.GetAscii(bidiStrippedHost);
return s_idnMapping.GetAscii(bidiStrippedHost);
}
catch (ArgumentException)
{
throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
}
return asciiForm;
}
}
@@ -370,13 +368,11 @@ namespace System
//
internal static unsafe string UnicodeEquivalent(string idnHost, char* hostname, int start, int end)
{
IdnMapping map = new IdnMapping();
// Test common scenario first for perf
// try to get unicode equivalent
try
{
return map.GetUnicode(idnHost);
return s_idnMapping.GetUnicode(idnHost);
}
catch (ArgumentException)
{
@@ -390,8 +386,6 @@ namespace System
internal static unsafe string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
{
IdnMapping map = new IdnMapping();
// hostname already validated
allAscii = true;
atLeastOneValidIdn = false;
@@ -454,14 +448,14 @@ namespace System
string asciiForm = unescapedHostname.Substring(curPos, newPos - curPos);
try
{
asciiForm = map.GetAscii(asciiForm);
asciiForm = s_idnMapping.GetAscii(asciiForm);
}
catch (ArgumentException)
{
throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
}
unicodeEqvlHost += map.GetUnicode(asciiForm);
unicodeEqvlHost += s_idnMapping.GetUnicode(asciiForm);
if (foundDot)
unicodeEqvlHost += ".";
}
@@ -473,7 +467,7 @@ namespace System
// check ace validity
try
{
unicodeEqvlHost += map.GetUnicode(unescapedHostname.Substring(curPos, newPos - curPos));
unicodeEqvlHost += s_idnMapping.GetUnicode(unescapedHostname, curPos, newPos - curPos);
if (foundDot)
unicodeEqvlHost += ".";
aceValid = true;
@@ -505,16 +499,20 @@ namespace System
// DNS specification [RFC 1035]. We use our own variant of IsLetterOrDigit
// because the base version returns false positives for non-ANSI characters
//
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsASCIILetterOrDigit(char character, ref bool notCanonical)
{
if ((character >= 'a' && character <= 'z') || (character >= '0' && character <= '9'))
if ((uint)(character - 'a') <= 'z' - 'a' || (uint)(character - '0') <= '9' - '0')
{
return true;
}
if (character >= 'A' && character <= 'Z')
if ((uint)(character - 'A') <= 'Z' - 'A')
{
notCanonical = true;
return true;
}
return false;
}
@@ -522,16 +520,20 @@ namespace System
// Takes into account the additional legal domain name characters '-' and '_'
// Note that '_' char is formally invalid but is historically in use, especially on corpnets
//
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsValidDomainLabelCharacter(char character, ref bool notCanonical)
{
if ((character >= 'a' && character <= 'z') || (character >= '0' && character <= '9') || (character == '-') || (character == '_'))
if ((uint)(character - 'a') <= 'z' - 'a' || (uint)(character - '0') <= '9' - '0' || character == '-' || character == '_')
{
return true;
}
if (character >= 'A' && character <= 'Z')
if ((uint)(character - 'A') <= 'Z' - 'A')
{
notCanonical = true;
return true;
}
return false;
}
}

View File

@@ -27,7 +27,18 @@ namespace System
{
byte* numbers = stackalloc byte[NumberOfLabels];
isLoopback = Parse(str, numbers, start, end);
return numbers[0] + "." + numbers[1] + "." + numbers[2] + "." + numbers[3];
Span<char> stackSpace = stackalloc char[NumberOfLabels * 3 + 3];
int totalChars = 0, charsWritten;
for (int i = 0; i < 3; i++)
{
numbers[i].TryFormat(stackSpace.Slice(totalChars), out charsWritten);
int periodPos = totalChars + charsWritten;
stackSpace[periodPos] = '.';
totalChars = periodPos + 1;
}
numbers[3].TryFormat(stackSpace.Slice(totalChars), out charsWritten);
return new string(stackSpace.Slice(0, totalChars + charsWritten));
}
}
@@ -184,7 +195,7 @@ namespace System
{
int numberBase = Decimal;
char ch;
long[] parts = new long[4];
Span<long> parts = stackalloc long[4];
long currentValue = 0;
bool atLeastOneChar = false;

View File

@@ -1 +1 @@
ebf064fad2d61a6c755274f7cfa67fb959e7dc48
fcc1b9ea14bc7cb776e86beed29fff64c4a5c2e6

View File

@@ -540,5 +540,32 @@ namespace System.PrivateUri.Tests
Assert.Equal(authority, fileTwoSlashes.Authority); // Two slashes must be followed by an authority
Assert.Equal(authority, fileFourSlashes.Authority); // More than three slashes looks like a UNC share
}
[Theory]
[InlineData(@"c:/path/with/unicode/ö/test.xml")]
[InlineData(@"file://c:/path/with/unicode/ö/test.xml")]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Iri_WindowsPathWithUnicode_DoesRemoveScheme(string uriString)
{
var uri = new Uri(uriString);
Assert.False(uri.LocalPath.StartsWith("file:"));
}
[Theory]
[InlineData("http:%C3%A8")]
[InlineData("http:\u00E8")]
[InlineData("%C3%A8")]
[InlineData("\u00E8")]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Requires fix shipping in .NET 4.7.2")]
public void Iri_RelativeUriCreation_ShouldNotNormalize(string uriString)
{
Uri href;
Uri hrefAbsolute;
Uri baseIri = new Uri("http://www.contoso.com");
Assert.True(Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out href));
Assert.True(Uri.TryCreate(baseIri, href, out hrefAbsolute));
Assert.Equal("http://www.contoso.com/%C3%A8", hrefAbsolute.AbsoluteUri);
}
}
}