diff --git a/VAR.HttpServer.sln b/VAR.HttpServer.sln index adfc365..7e9affa 100644 --- a/VAR.HttpServer.sln +++ b/VAR.HttpServer.sln @@ -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 diff --git a/VAR.HttpServer/HttpUtility.cs b/VAR.HttpServer/HttpUtility.cs index 6c24ff7..68ba9fd 100644 --- a/VAR.HttpServer/HttpUtility.cs +++ b/VAR.HttpServer/HttpUtility.cs @@ -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(); @@ -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(); + } } } diff --git a/VAR.HttpServer/Properties/AssemblyInfo.cs b/VAR.HttpServer/Properties/AssemblyInfo.cs index 06f09d8..7d8552f 100644 --- a/VAR.HttpServer/Properties/AssemblyInfo.cs +++ b/VAR.HttpServer/Properties/AssemblyInfo.cs @@ -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)] diff --git a/VAR.HttpServerTests/HttpUtilityTests.cs b/VAR.HttpServerTests/HttpUtilityTests.cs new file mode 100644 index 0000000..fc78409 --- /dev/null +++ b/VAR.HttpServerTests/HttpUtilityTests.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/VAR.HttpServerTests/Properties/AssemblyInfo.cs b/VAR.HttpServerTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aba9650 --- /dev/null +++ b/VAR.HttpServerTests/Properties/AssemblyInfo.cs @@ -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")] diff --git a/VAR.HttpServerTests/VAR.HttpServerTests.csproj b/VAR.HttpServerTests/VAR.HttpServerTests.csproj new file mode 100644 index 0000000..1da4dfe --- /dev/null +++ b/VAR.HttpServerTests/VAR.HttpServerTests.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + {1D73D51B-D094-4775-93A4-A26F8B66C167} + Library + Properties + VAR.HttpServerTests + VAR.HttpServerTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {E865BA90-11F7-46D4-B718-A536B0B76C35} + VAR.HttpServer + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file