Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@@ -2,7 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.1.0</AssemblyVersion>
<AssemblyKey>Open</AssemblyKey>
<IsNETCoreApp>true</IsNETCoreApp>
<IsUAP>true</IsUAP>
</PropertyGroup>

View File

@@ -283,45 +283,14 @@ namespace System.Web.Util
}
else if (b == '%' && i < count - 2)
{
if (bytes[pos + 1] == 'u' && i < count - 5)
{
int h1 = HttpEncoderUtility.HexToInt((char)bytes[pos + 2]);
int h2 = HttpEncoderUtility.HexToInt((char)bytes[pos + 3]);
int h3 = HttpEncoderUtility.HexToInt((char)bytes[pos + 4]);
int h4 = HttpEncoderUtility.HexToInt((char)bytes[pos + 5]);
int h1 = HttpEncoderUtility.HexToInt((char)bytes[pos + 1]);
int h2 = HttpEncoderUtility.HexToInt((char)bytes[pos + 2]);
if (h1 >= 0 && h2 >= 0 && h3 >= 0 && h4 >= 0)
{
// valid 4 hex chars
char ch = (char)((h1 << 12) | (h2 << 8) | (h3 << 4) | h4);
i += 5;
byte[] chBytes = Encoding.UTF8.GetBytes(new[] { ch });
if (chBytes.Length == 1)
{
b = chBytes[0];
}
else
{
for (int j = 0; j < chBytes.Length - 1; j++)
{
decodedBytes[decodedBytesCount++] = chBytes[j];
}
b = chBytes[chBytes.Length - 1];
}
}
}
else
{
int h1 = HttpEncoderUtility.HexToInt((char)bytes[pos + 1]);
int h2 = HttpEncoderUtility.HexToInt((char)bytes[pos + 2]);
if (h1 >= 0 && h2 >= 0)
{
// valid 2 hex chars
b = (byte)((h1 << 4) | h2);
i += 2;
}
if (h1 >= 0 && h2 >= 0)
{
// valid 2 hex chars
b = (byte)((h1 << 4) | h2);
i += 2;
}
}

View File

@@ -1,7 +1,34 @@
// 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.
//
// System.Web.HttpUtilityTest.cs - Unit tests for System.Web.HttpUtility
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -9,7 +36,7 @@ using System.Text;
using System.Web;
using Xunit;
namespace System.Collections.Specialized.Tests
namespace System.Web.Tests
{
public class HttpUtilityTest
{
@@ -403,6 +430,19 @@ namespace System.Collections.Specialized.Tests
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=b%uu0061r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%uu0061r"},
};
public static IEnumerable<object[]> UrlDecodeDataToBytes =>
new[]
{
new object[] { "http://127.0.0.1:8080/appDir/page.aspx?foo=bar", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%61r"},
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=b%ar", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%%61r"},
new object[] {"http://127.0.0.1:8080/app%Dir/page.aspx?foo=b%ar", "http://127.0.0.1:8080/app%Dir/page.aspx?foo=b%%61r"},
new object[] {"http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r", "http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r"},
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=ba%r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%61%r"},
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=b%uu0061r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%uu0061r"},
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=b%u0061r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%u0061r"},
new object[] {"http://127.0.0.1:8080/appDir/page.aspx?foo=b%%u0061r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%%u0061r"},
};
[Theory]
[MemberData(nameof(UrlDecodeData))]
public void UrlDecode(string decoded, string encoded)
@@ -411,7 +451,7 @@ namespace System.Collections.Specialized.Tests
}
[Theory]
[MemberData(nameof(UrlDecodeData))]
[MemberData(nameof(UrlDecodeDataToBytes))]
public void UrlDecodeToBytes(string decoded, string encoded)
{
Assert.Equal(decoded, Encoding.UTF8.GetString(HttpUtility.UrlDecodeToBytes(encoded, Encoding.UTF8)));