You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
53
external/corefx/src/System.Web.HttpUtility/System.Web.HttpUtility.sln
vendored
Normal file
53
external/corefx/src/System.Web.HttpUtility/System.Web.HttpUtility.sln
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.HttpUtility.Tests", "tests\System.Web.HttpUtility.Tests.csproj", "{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88} = {53D09AF4-0C13-4197-B8AD-9746F0374E88}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{350C956A-B4ED-4376-9B04-2908528D10FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.HttpUtility", "ref\System.Web.HttpUtility.csproj", "{14FAFC3A-8266-45C7-8604-8C2CB567E50D}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827B5CCD-073A-4A75-9661-73D54F0A3528}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.HttpUtility", "src\System.Web.HttpUtility.csproj", "{53D09AF4-0C13-4197-B8AD-9746F0374E88}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{096E7AD0-17A2-4EAF-9AC5-2F0FC67A4112}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU = DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU
|
||||
ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU = ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU
|
||||
DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU = DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU
|
||||
ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU = ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Debug|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.Build.0 = netstandard1.3-Debug|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Release|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.Build.0 = netstandard1.3-Release|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Debug|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.Build.0 = netstandard1.3-Debug|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Release|Any CPU
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.Build.0 = netstandard1.3-Release|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.ActiveCfg = net46-Windows_NT-Debug|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.DebugNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.Build.0 = net46-Windows_NT-Debug|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.ActiveCfg = net46-Windows_NT-Release|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.ReleaseNETCoreAppnet46-Windows_NTnetstandard1.3|AnyCPU.Build.0 = net46-Windows_NT-Release|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Debug|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.DebugNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.Build.0 = netstandard1.3-Debug|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.ActiveCfg = netstandard1.3-Release|Any CPU
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.ReleaseNETCoreAppnetstandard1.3netstandard1.3|AnyCPU.Build.0 = netstandard1.3-Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726} = {0D1E2954-A5C7-4B8C-932A-31EB4A96A726}
|
||||
{53D09AF4-0C13-4197-B8AD-9746F0374E88} = {53D09AF4-0C13-4197-B8AD-9746F0374E88}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
8
external/corefx/src/System.Web.HttpUtility/dir.props
vendored
Normal file
8
external/corefx/src/System.Web.HttpUtility/dir.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-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>
|
||||
<IsNETCoreApp>true</IsNETCoreApp>
|
||||
</PropertyGroup>
|
||||
</Project>
|
9
external/corefx/src/System.Web.HttpUtility/ref/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Web.HttpUtility/ref/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netcoreapp;
|
||||
uap;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
43
external/corefx/src/System.Web.HttpUtility/ref/System.Web.HttpUtility.cs
vendored
Normal file
43
external/corefx/src/System.Web.HttpUtility/ref/System.Web.HttpUtility.cs
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
// ------------------------------------------------------------------------------
|
||||
// Changes to this file must follow the http://aka.ms/api-review process.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web {
|
||||
public sealed class HttpUtility {
|
||||
public static string HtmlAttributeEncode(string s) { throw null; }
|
||||
public static void HtmlAttributeEncode(string s, System.IO.TextWriter output) { }
|
||||
public static string HtmlDecode(string s) { throw null; }
|
||||
public static void HtmlDecode(string s, System.IO.TextWriter output) { }
|
||||
public static string HtmlEncode(string s) { throw null; }
|
||||
public static string HtmlEncode(object value) { throw null; }
|
||||
public static void HtmlEncode(string s, System.IO.TextWriter output) { }
|
||||
public static string JavaScriptStringEncode(string value) { throw null; }
|
||||
public static string JavaScriptStringEncode(string value, bool addDoubleQuotes) { throw null; }
|
||||
public static System.Collections.Specialized.NameValueCollection ParseQueryString(string query) { throw null; }
|
||||
public static System.Collections.Specialized.NameValueCollection ParseQueryString(string query, System.Text.Encoding encoding) { throw null; }
|
||||
public static string UrlDecode(string str, System.Text.Encoding e) { throw null; }
|
||||
public static string UrlDecode(byte[] bytes, int offset, int count, System.Text.Encoding e) { throw null; }
|
||||
public static string UrlDecode(string str) { throw null; }
|
||||
public static string UrlDecode(byte[] bytes, System.Text.Encoding e) { throw null; }
|
||||
public static byte[] UrlDecodeToBytes(string str) { throw null; }
|
||||
public static byte[] UrlDecodeToBytes(string str, System.Text.Encoding e) { throw null; }
|
||||
public static byte[] UrlDecodeToBytes(byte[] bytes) { throw null; }
|
||||
public static byte[] UrlDecodeToBytes(byte[] bytes, int offset, int count) { throw null; }
|
||||
public static string UrlEncode(string str) { throw null; }
|
||||
public static string UrlEncode(string str, System.Text.Encoding e) { throw null; }
|
||||
public static string UrlEncode(byte[] bytes) { throw null; }
|
||||
public static string UrlEncode(byte[] bytes, int offset, int count) { throw null; }
|
||||
public static byte[] UrlEncodeToBytes(string str) { throw null; }
|
||||
public static byte[] UrlEncodeToBytes(byte[] bytes) { throw null; }
|
||||
public static byte[] UrlEncodeToBytes(string str, System.Text.Encoding e) { throw null; }
|
||||
public static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count) { throw null; }
|
||||
[Obsolete("This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncode(String).")]
|
||||
public static string UrlEncodeUnicode(string str) { throw null; }
|
||||
[Obsolete("This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncodeToBytes(String).")]
|
||||
public static byte[] UrlEncodeUnicodeToBytes(string str) { throw null; }
|
||||
public static string UrlPathEncode(string str) { throw null; }
|
||||
}
|
||||
}
|
19
external/corefx/src/System.Web.HttpUtility/ref/System.Web.HttpUtility.csproj
vendored
Normal file
19
external/corefx/src/System.Web.HttpUtility/ref/System.Web.HttpUtility.csproj
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="System.Web.HttpUtility.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\System.Collections.Specialized\ref\System.Collections.Specialized.csproj" />
|
||||
<ProjectReference Include="..\..\System.IO\ref\System.IO.csproj" />
|
||||
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
|
||||
<ProjectReference Include="..\..\System.Runtime.Extensions\ref\System.Runtime.Extensions.csproj" />
|
||||
<ProjectReference Include="..\..\System.Text.Encoding\ref\System.Text.Encoding.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
10
external/corefx/src/System.Web.HttpUtility/src/Configurations.props
vendored
Normal file
10
external/corefx/src/System.Web.HttpUtility/src/Configurations.props
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
net46-Windows_NT;
|
||||
netcoreapp;
|
||||
uap;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
37
external/corefx/src/System.Web.HttpUtility/src/System.Web.HttpUtility.csproj
vendored
Normal file
37
external/corefx/src/System.Web.HttpUtility/src/System.Web.HttpUtility.csproj
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{53D09AF4-0C13-4197-B8AD-9746F0374E88}</ProjectGuid>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetGroup)'=='net46'">true</IsPartialFacadeAssembly>
|
||||
</PropertyGroup>
|
||||
<!-- Default configurations to help VS understand the options -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net46-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
|
||||
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
|
||||
<Compile Include="System\Web\HttpUtility.cs" />
|
||||
<Compile Include="System\Web\Util\HttpEncoder.cs" />
|
||||
<Compile Include="System\Web\Util\HttpEncoderUtility.cs" />
|
||||
<Compile Include="System\Web\Util\UriUtil.cs" />
|
||||
<Compile Include="System\Web\Util\Utf16StringValidator.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'net46'">
|
||||
<TargetingPackReference Include="System.Web" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Collections.Specialized" />
|
||||
<Reference Include="System.Diagnostics.Debug" />
|
||||
<Reference Include="System.Diagnostics.Tools" />
|
||||
<Reference Include="System.Globalization" />
|
||||
<Reference Include="System.IO" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.Extensions" />
|
||||
<Reference Include="System.Text.Encoding" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
301
external/corefx/src/System.Web.HttpUtility/src/System/Web/HttpUtility.cs
vendored
Normal file
301
external/corefx/src/System.Web.HttpUtility/src/System/Web/HttpUtility.cs
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
// 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.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web.Util;
|
||||
|
||||
namespace System.Web
|
||||
{
|
||||
public sealed class HttpUtility
|
||||
{
|
||||
private sealed class HttpQSCollection : NameValueCollection
|
||||
{
|
||||
internal HttpQSCollection()
|
||||
: base(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
int count = Count;
|
||||
if (count == 0)
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string[] keys = AllKeys;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
sb.AppendFormat("{0}={1}&", keys[i], UrlEncode(this[keys[i]]));
|
||||
}
|
||||
if (sb.Length > 0)
|
||||
sb.Length--;
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static NameValueCollection ParseQueryString(string query)
|
||||
{
|
||||
return ParseQueryString(query, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static NameValueCollection ParseQueryString(string query, Encoding encoding)
|
||||
{
|
||||
if (query == null)
|
||||
throw new ArgumentNullException(nameof(query));
|
||||
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException(nameof(encoding));
|
||||
|
||||
if ((query.Length > 0) && (query[0] == '?'))
|
||||
query = query.Substring(1);
|
||||
|
||||
var result = new HttpQSCollection();
|
||||
ParseQueryString(query, encoding, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ParseQueryString(string query, Encoding encoding, NameValueCollection result)
|
||||
{
|
||||
if (query.Length == 0)
|
||||
return;
|
||||
|
||||
var decoded = HtmlDecode(query);
|
||||
var decodedLength = decoded.Length;
|
||||
var namePos = 0;
|
||||
var first = true;
|
||||
while (namePos <= decodedLength)
|
||||
{
|
||||
int valuePos = -1, valueEnd = -1;
|
||||
for (var q = namePos; q < decodedLength; q++)
|
||||
if ((valuePos == -1) && (decoded[q] == '='))
|
||||
{
|
||||
valuePos = q + 1;
|
||||
}
|
||||
else if (decoded[q] == '&')
|
||||
{
|
||||
valueEnd = q;
|
||||
break;
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
if (decoded[namePos] == '?')
|
||||
namePos++;
|
||||
}
|
||||
|
||||
string name;
|
||||
if (valuePos == -1)
|
||||
{
|
||||
name = null;
|
||||
valuePos = namePos;
|
||||
}
|
||||
else
|
||||
{
|
||||
name = UrlDecode(decoded.Substring(namePos, valuePos - namePos - 1), encoding);
|
||||
}
|
||||
if (valueEnd < 0)
|
||||
{
|
||||
namePos = -1;
|
||||
valueEnd = decoded.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
namePos = valueEnd + 1;
|
||||
}
|
||||
var value = UrlDecode(decoded.Substring(valuePos, valueEnd - valuePos), encoding);
|
||||
|
||||
result.Add(name, value);
|
||||
if (namePos == -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string HtmlDecode(string s)
|
||||
{
|
||||
return HttpEncoder.HtmlDecode(s);
|
||||
}
|
||||
|
||||
|
||||
public static void HtmlDecode(string s, TextWriter output)
|
||||
{
|
||||
HttpEncoder.HtmlDecode(s, output);
|
||||
}
|
||||
|
||||
|
||||
public static string HtmlEncode(string s)
|
||||
{
|
||||
return HttpEncoder.HtmlEncode(s);
|
||||
}
|
||||
|
||||
|
||||
public static string HtmlEncode(object value)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
return HtmlEncode(Convert.ToString(value, CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
|
||||
public static void HtmlEncode(string s, TextWriter output)
|
||||
{
|
||||
HttpEncoder.HtmlEncode(s, output);
|
||||
}
|
||||
|
||||
|
||||
public static string HtmlAttributeEncode(string s)
|
||||
{
|
||||
return HttpEncoder.HtmlAttributeEncode(s);
|
||||
}
|
||||
|
||||
|
||||
public static void HtmlAttributeEncode(string s, TextWriter output)
|
||||
{
|
||||
HttpEncoder.HtmlAttributeEncode(s, output);
|
||||
}
|
||||
|
||||
public static string UrlEncode(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return UrlEncode(str, Encoding.UTF8);
|
||||
}
|
||||
|
||||
|
||||
public static string UrlPathEncode(string str)
|
||||
{
|
||||
return HttpEncoder.UrlPathEncode(str);
|
||||
}
|
||||
|
||||
public static string UrlEncode(string str, Encoding e)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return Encoding.ASCII.GetString(UrlEncodeToBytes(str, e));
|
||||
}
|
||||
|
||||
public static string UrlEncode(byte[] bytes)
|
||||
{
|
||||
if (bytes == null)
|
||||
return null;
|
||||
return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes));
|
||||
}
|
||||
|
||||
public static string UrlEncode(byte[] bytes, int offset, int count)
|
||||
{
|
||||
if (bytes == null)
|
||||
return null;
|
||||
return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, offset, count));
|
||||
}
|
||||
|
||||
public static byte[] UrlEncodeToBytes(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return UrlEncodeToBytes(str, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static byte[] UrlEncodeToBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes == null)
|
||||
return null;
|
||||
return UrlEncodeToBytes(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
[Obsolete(
|
||||
"This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncodeToBytes(String)."
|
||||
)]
|
||||
public static byte[] UrlEncodeUnicodeToBytes(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return Encoding.ASCII.GetBytes(UrlEncodeUnicode(str));
|
||||
}
|
||||
|
||||
public static string UrlDecode(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return UrlDecode(str, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static string UrlDecode(byte[] bytes, Encoding e)
|
||||
{
|
||||
if (bytes == null)
|
||||
return null;
|
||||
return UrlDecode(bytes, 0, bytes.Length, e);
|
||||
}
|
||||
|
||||
public static byte[] UrlDecodeToBytes(string str)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return UrlDecodeToBytes(str, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static byte[] UrlDecodeToBytes(string str, Encoding e)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return UrlDecodeToBytes(e.GetBytes(str));
|
||||
}
|
||||
|
||||
public static byte[] UrlDecodeToBytes(byte[] bytes)
|
||||
{
|
||||
if (bytes == null)
|
||||
return null;
|
||||
return UrlDecodeToBytes(bytes, 0, bytes != null ? bytes.Length : 0);
|
||||
}
|
||||
|
||||
public static byte[] UrlEncodeToBytes(string str, Encoding e)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
var bytes = e.GetBytes(str);
|
||||
return HttpEncoder.UrlEncode(bytes, 0, bytes.Length, false /* alwaysCreateNewReturnValue */);
|
||||
}
|
||||
|
||||
public static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count)
|
||||
{
|
||||
return HttpEncoder.UrlEncode(bytes, offset, count, true /* alwaysCreateNewReturnValue */);
|
||||
}
|
||||
|
||||
[Obsolete(
|
||||
"This method produces non-standards-compliant output and has interoperability issues. The preferred alternative is UrlEncode(String)."
|
||||
)]
|
||||
public static string UrlEncodeUnicode(string str)
|
||||
{
|
||||
return HttpEncoder.UrlEncodeUnicode(str, false /* ignoreAscii */);
|
||||
}
|
||||
|
||||
public static string UrlDecode(string str, Encoding e)
|
||||
{
|
||||
return HttpEncoder.UrlDecode(str, e);
|
||||
}
|
||||
|
||||
public static string UrlDecode(byte[] bytes, int offset, int count, Encoding e)
|
||||
{
|
||||
return HttpEncoder.UrlDecode(bytes, offset, count, e);
|
||||
}
|
||||
|
||||
public static byte[] UrlDecodeToBytes(byte[] bytes, int offset, int count)
|
||||
{
|
||||
return HttpEncoder.UrlDecode(bytes, offset, count);
|
||||
}
|
||||
|
||||
public static string JavaScriptStringEncode(string value)
|
||||
{
|
||||
return JavaScriptStringEncode(value, false);
|
||||
}
|
||||
|
||||
public static string JavaScriptStringEncode(string value, bool addDoubleQuotes)
|
||||
{
|
||||
var encoded = HttpEncoder.JavaScriptStringEncode(value);
|
||||
return addDoubleQuotes ? "\"" + encoded + "\"" : encoded;
|
||||
}
|
||||
}
|
||||
}
|
786
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
vendored
Normal file
786
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
58
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/HttpEncoderUtility.cs
vendored
Normal file
58
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/HttpEncoderUtility.cs
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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;
|
||||
|
||||
namespace System.Web.Util
|
||||
{
|
||||
internal static class HttpEncoderUtility
|
||||
{
|
||||
public static int HexToInt(char h)
|
||||
{
|
||||
return (h >= '0' && h <= '9') ? h - '0' :
|
||||
(h >= 'a' && h <= 'f') ? h - 'a' + 10 :
|
||||
(h >= 'A' && h <= 'F') ? h - 'A' + 10 :
|
||||
-1;
|
||||
}
|
||||
|
||||
public static char IntToHex(int n)
|
||||
{
|
||||
Debug.Assert(n < 0x10);
|
||||
|
||||
if (n <= 9)
|
||||
return (char)(n + (int)'0');
|
||||
else
|
||||
return (char)(n - 10 + (int)'a');
|
||||
}
|
||||
|
||||
// Set of safe chars, from RFC 1738.4 minus '+'
|
||||
public static bool IsUrlSafeChar(char ch)
|
||||
{
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
|
||||
return true;
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '-':
|
||||
case '_':
|
||||
case '.':
|
||||
case '!':
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper to encode spaces only
|
||||
internal static string UrlEncodeSpaces(string str)
|
||||
{
|
||||
if (str != null && str.IndexOf(' ') >= 0)
|
||||
str = str.Replace(" ", "%20");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
70
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/UriUtil.cs
vendored
Normal file
70
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/UriUtil.cs
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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.
|
||||
|
||||
namespace System.Web.Util
|
||||
{
|
||||
internal static class UriUtil
|
||||
{
|
||||
private static readonly char[] s_queryFragmentSeparators = { '?', '#' };
|
||||
|
||||
// Just extracts the query string and fragment from the input path by splitting on the separator characters.
|
||||
// Doesn't perform any validation as to whether the input represents a valid URL.
|
||||
// Concatenating the pieces back together will form the original input string.
|
||||
private static void ExtractQueryAndFragment(string input, out string path, out string queryAndFragment)
|
||||
{
|
||||
int queryFragmentSeparatorPos = input.IndexOfAny(s_queryFragmentSeparators);
|
||||
if (queryFragmentSeparatorPos != -1)
|
||||
{
|
||||
path = input.Substring(0, queryFragmentSeparatorPos);
|
||||
queryAndFragment = input.Substring(queryFragmentSeparatorPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no query or fragment separator
|
||||
path = input;
|
||||
queryAndFragment = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to split a URI into its constituent pieces.
|
||||
// Even if this method returns true, one or more of the out parameters might contain a null or empty string, e.g. if there is no query / fragment.
|
||||
// Concatenating the pieces back together will form the original input string.
|
||||
internal static bool TrySplitUriForPathEncode(string input, out string schemeAndAuthority, out string path, out string queryAndFragment)
|
||||
{
|
||||
// Strip off ?query and #fragment if they exist, since we're not going to look at them
|
||||
string inputWithoutQueryFragment;
|
||||
ExtractQueryAndFragment(input, out inputWithoutQueryFragment, out queryAndFragment);
|
||||
|
||||
// Use Uri class to parse the url into authority and path, use that to help decide
|
||||
// where to split the string. Do not rebuild the url from the Uri instance, as that
|
||||
// might have subtle changes from the original string (for example, see below about "://").
|
||||
Uri uri;
|
||||
if (Uri.TryCreate(inputWithoutQueryFragment, UriKind.Absolute, out uri))
|
||||
{
|
||||
string authority = uri.Authority; // e.g. "foo:81" in "http://foo:81/bar"
|
||||
if (!string.IsNullOrEmpty(authority))
|
||||
{
|
||||
// don't make any assumptions about the scheme or the "://" part.
|
||||
// For example, the "//" could be missing, or there could be "///" as in "file:///C:\foo.txt"
|
||||
// To retain the same string as originally given, find the authority in the original url and include
|
||||
// everything up to that.
|
||||
int authorityIndex = inputWithoutQueryFragment.IndexOf(authority, StringComparison.OrdinalIgnoreCase);
|
||||
if (authorityIndex != -1)
|
||||
{
|
||||
int schemeAndAuthorityLength = authorityIndex + authority.Length;
|
||||
schemeAndAuthority = inputWithoutQueryFragment.Substring(0, schemeAndAuthorityLength);
|
||||
path = inputWithoutQueryFragment.Substring(schemeAndAuthorityLength);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Not a safe URL
|
||||
schemeAndAuthority = null;
|
||||
path = null;
|
||||
queryAndFragment = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
71
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/Utf16StringValidator.cs
vendored
Normal file
71
external/corefx/src/System.Web.HttpUtility/src/System/Web/Util/Utf16StringValidator.cs
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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.
|
||||
|
||||
namespace System.Web.Util
|
||||
{
|
||||
internal static class Utf16StringValidator
|
||||
{
|
||||
private const char UNICODE_REPLACEMENT_CHAR = '\uFFFD';
|
||||
|
||||
internal static string ValidateString(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
// locate the first surrogate character
|
||||
int idxOfFirstSurrogate = -1;
|
||||
for (int i = 0; i < input.Length; i++)
|
||||
{
|
||||
if (char.IsSurrogate(input[i]))
|
||||
{
|
||||
idxOfFirstSurrogate = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// fast case: no surrogates = return input string
|
||||
if (idxOfFirstSurrogate < 0)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
// slow case: surrogates exist, so we need to validate them
|
||||
char[] chars = input.ToCharArray();
|
||||
for (int i = idxOfFirstSurrogate; i < chars.Length; i++)
|
||||
{
|
||||
char thisChar = chars[i];
|
||||
|
||||
// If this character is a low surrogate, then it was not preceded by
|
||||
// a high surrogate, so we'll replace it.
|
||||
if (char.IsLowSurrogate(thisChar))
|
||||
{
|
||||
chars[i] = UNICODE_REPLACEMENT_CHAR;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char.IsHighSurrogate(thisChar))
|
||||
{
|
||||
// If this character is a high surrogate and it is followed by a
|
||||
// low surrogate, allow both to remain.
|
||||
if (i + 1 < chars.Length && char.IsLowSurrogate(chars[i + 1]))
|
||||
{
|
||||
i++; // skip the low surrogate also
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this character is a high surrogate and it is not followed
|
||||
// by a low surrogate, replace it.
|
||||
chars[i] = UNICODE_REPLACEMENT_CHAR;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise, this is a non-surrogate character and just move to the
|
||||
// next character.
|
||||
}
|
||||
return new string(chars);
|
||||
}
|
||||
}
|
||||
}
|
8
external/corefx/src/System.Web.HttpUtility/tests/Configurations.props
vendored
Normal file
8
external/corefx/src/System.Web.HttpUtility/tests/Configurations.props
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard1.3;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
559
external/corefx/src/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs
vendored
Normal file
559
external/corefx/src/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs
vendored
Normal file
File diff suppressed because one or more lines are too long
10
external/corefx/src/System.Web.HttpUtility/tests/System.Web.HttpUtility.Tests.builds
vendored
Normal file
10
external/corefx/src/System.Web.HttpUtility/tests/System.Web.HttpUtility.Tests.builds
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<Project Include="System.Web.HttpUtility.Tests.csproj">
|
||||
<TestTFMs>netcoreapp;netcoreapp1.0;net46</TestTFMs>
|
||||
</Project>
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
|
||||
</Project>
|
13
external/corefx/src/System.Web.HttpUtility/tests/System.Web.HttpUtility.Tests.csproj
vendored
Normal file
13
external/corefx/src/System.Web.HttpUtility/tests/System.Web.HttpUtility.Tests.csproj
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard1.3-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
<Compile Include="HttpUtility\HttpUtilityTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
Reference in New Issue
Block a user