HttpUtility: Add UrlEncode.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.572
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30204.135
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.HttpServer", "VAR.HttpServer\VAR.HttpServer.csproj", "{E865BA90-11F7-46D4-B718-A536B0B76C35}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.HttpServer.MiniServerTest", "VAR.HttpServer.MiniServerTest\VAR.HttpServer.MiniServerTest.csproj", "{6BD47B75-3DC2-4559-9311-E3D8117D4A89}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.HttpServerTests", "VAR.HttpServerTests\VAR.HttpServerTests.csproj", "{1D73D51B-D094-4775-93A4-A26F8B66C167}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -21,6 +23,10 @@ Global
|
||||
{6BD47B75-3DC2-4559-9311-E3D8117D4A89}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6BD47B75-3DC2-4559-9311-E3D8117D4A89}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6BD47B75-3DC2-4559-9311-E3D8117D4A89}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1D73D51B-D094-4775-93A4-A26F8B66C167}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1D73D51B-D094-4775-93A4-A26F8B66C167}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1D73D51B-D094-4775-93A4-A26F8B66C167}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1D73D51B-D094-4775-93A4-A26F8B66C167}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -15,10 +15,7 @@ namespace VAR.HttpServer
|
||||
return str;
|
||||
}
|
||||
|
||||
if (e == null)
|
||||
{
|
||||
e = Encoding.UTF8;
|
||||
}
|
||||
if (e == null) { e = Encoding.UTF8; }
|
||||
|
||||
long len = str.Length;
|
||||
var bytes = new List<byte>();
|
||||
@@ -123,5 +120,27 @@ namespace VAR.HttpServer
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public static string UrlEncode(string str, Encoding e = null)
|
||||
{
|
||||
StringBuilder sbOutput = new StringBuilder();
|
||||
if (e == null) { e = Encoding.UTF8; }
|
||||
byte[] bytes = e.GetBytes(str);
|
||||
foreach (byte c in bytes)
|
||||
{
|
||||
if (c == ' ')
|
||||
{
|
||||
sbOutput.Append('+');
|
||||
continue;
|
||||
}
|
||||
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||
{
|
||||
sbOutput.Append((char)c);
|
||||
continue;
|
||||
}
|
||||
sbOutput.AppendFormat("%{0:X2}", (int)c);
|
||||
}
|
||||
return sbOutput.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("VAR")]
|
||||
[assembly: AssemblyProduct("VAR.HttpServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2019")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2019-2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
30
VAR.HttpServerTests/HttpUtilityTests.cs
Normal file
30
VAR.HttpServerTests/HttpUtilityTests.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace VAR.HttpServer.Tests
|
||||
{
|
||||
[TestClass()]
|
||||
public class HttpUtilityTests
|
||||
{
|
||||
[TestMethod()]
|
||||
public void UrlEncode__UrlDecode__TestWithAsciiSymbols()
|
||||
{
|
||||
string strOrigin = "Hello World! $%&//();@!";
|
||||
|
||||
string strEncoded = HttpUtility.UrlEncode(strOrigin);
|
||||
string strDecoded = HttpUtility.UrlDecode(strEncoded);
|
||||
|
||||
Assert.AreEqual(strOrigin, strDecoded);
|
||||
}
|
||||
|
||||
[TestMethod()]
|
||||
public void UrlEncode__UrlDecode__TestWithLocalSymbols()
|
||||
{
|
||||
string strOrigin = "Hello World! ¿?¡! ñÑ áéíóú ";
|
||||
|
||||
string strEncoded = HttpUtility.UrlEncode(strOrigin);
|
||||
string strDecoded = HttpUtility.UrlDecode(strEncoded);
|
||||
|
||||
Assert.AreEqual(strOrigin, strDecoded);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
VAR.HttpServerTests/Properties/AssemblyInfo.cs
Normal file
15
VAR.HttpServerTests/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("VAR.HttpServerTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("VAR")]
|
||||
[assembly: AssemblyProduct("VAR.HttpServerTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("1d73d51b-d094-4775-93a4-a26f8b66c167")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
90
VAR.HttpServerTests/VAR.HttpServerTests.csproj
Normal file
90
VAR.HttpServerTests/VAR.HttpServerTests.csproj
Normal file
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1D73D51B-D094-4775-93A4-A26F8B66C167}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>VAR.HttpServerTests</RootNamespace>
|
||||
<AssemblyName>VAR.HttpServerTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="HttpUtilityTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VAR.HttpServer\VAR.HttpServer.csproj">
|
||||
<Project>{E865BA90-11F7-46D4-B718-A536B0B76C35}</Project>
|
||||
<Name>VAR.HttpServer</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user