-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
277 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<!-- Configurations that affect the Test Framework --> | ||
<RunConfiguration> | ||
<MaxCpuCount>1</MaxCpuCount> | ||
<ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory --> | ||
<TestSessionTimeout>120000</TestSessionTimeout><!-- Milliseconds --> | ||
<TargetFrameworkVersion>net48</TargetFrameworkVersion> | ||
<TargetPlatform>x64</TargetPlatform> | ||
</RunConfiguration> | ||
<nanoFrameworkAdapter> | ||
<Logging>None</Logging> | ||
<IsRealHardware>False</IsRealHardware> | ||
</nanoFrameworkAdapter> | ||
</RunSettings> | ||
<!-- Configurations that affect the Test Framework --> | ||
<RunConfiguration> | ||
<MaxCpuCount>1</MaxCpuCount> | ||
<ResultsDirectory>.\TestResults</ResultsDirectory> | ||
<!-- Path relative to solution directory --> | ||
<TestSessionTimeout>60000</TestSessionTimeout> | ||
<!-- Milliseconds --> | ||
<TargetFrameworkVersion>net48</TargetFrameworkVersion> | ||
<TargetPlatform>x64</TargetPlatform> | ||
</RunConfiguration> | ||
<nanoFrameworkAdapter> | ||
<Logging>Detailed</Logging> | ||
<IsRealHardware>False</IsRealHardware> | ||
</nanoFrameworkAdapter> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using nanoFramework.TestFramework; | ||
using System; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Web; | ||
|
||
namespace HttpUnitTests | ||
{ | ||
[TestClass] | ||
public class HttpUtilityTest | ||
{ | ||
|
||
[TestMethod] | ||
public void UrlDecodeNoThrow() | ||
{ | ||
string str = "../../&param2=%CURRREV%"; | ||
|
||
Assert.Equal(str, HttpUtility.UrlDecode(str)); | ||
} | ||
|
||
[TestMethod] | ||
public void UrlEncodeTest() | ||
{ | ||
for (char c = char.MinValue; c < char.MaxValue; c++) | ||
{ | ||
byte[] bIn; | ||
bIn = Encoding.UTF8.GetBytes(c.ToString()); | ||
MemoryStream expected = new MemoryStream(); | ||
MemoryStream expUnicode = new MemoryStream(); | ||
|
||
// build expected result for UrlEncode | ||
for (int i = 0; i < bIn.Length; i++) | ||
{ | ||
UrlEncodeChar((char)bIn[i], expected, false); | ||
} | ||
|
||
// build expected result for UrlEncodeUnicode | ||
UrlEncodeChar(c, expUnicode, true); | ||
|
||
byte[] bOut = expected.ToArray(); | ||
|
||
Assert.Equal( | ||
Encoding.UTF8.GetString(bOut, 0, bOut.Length), | ||
HttpUtility.UrlEncode(c.ToString()), | ||
$"Expecting UrlEncode of '{c}' ({(int)c}) as [{Encoding.UTF8.GetString(bOut, 0, bOut.Length)}] got {HttpUtility.UrlEncode(c.ToString())}"); | ||
} | ||
} | ||
|
||
static void UrlEncodeChar(char c, Stream result, bool isUnicode) | ||
{ | ||
if (c > 255) | ||
{ | ||
int idx; | ||
int i = (int)c; | ||
|
||
result.WriteByte((byte)'%'); | ||
result.WriteByte((byte)'u'); | ||
idx = i >> 12; | ||
result.WriteByte((byte)hexChars[idx]); | ||
idx = (i >> 8) & 0x0F; | ||
result.WriteByte((byte)hexChars[idx]); | ||
idx = (i >> 4) & 0x0F; | ||
result.WriteByte((byte)hexChars[idx]); | ||
idx = i & 0x0F; | ||
result.WriteByte((byte)hexChars[idx]); | ||
return; | ||
} | ||
|
||
if (c > ' ' && notEncoded.IndexOf(c) != -1) | ||
{ | ||
result.WriteByte((byte)c); | ||
return; | ||
} | ||
if (c == ' ') | ||
{ | ||
result.WriteByte((byte)'+'); | ||
return; | ||
} | ||
if ((c < '0') || | ||
(c < 'A' && c > '9') || | ||
(c > 'Z' && c < 'a') || | ||
(c > 'z')) | ||
{ | ||
if (isUnicode && c > 127) | ||
{ | ||
result.WriteByte((byte)'%'); | ||
result.WriteByte((byte)'u'); | ||
result.WriteByte((byte)'0'); | ||
result.WriteByte((byte)'0'); | ||
} | ||
else | ||
{ | ||
result.WriteByte((byte)'%'); | ||
} | ||
|
||
int idx = ((int)c) >> 4; | ||
result.WriteByte((byte)hexChars[idx]); | ||
idx = c & 0x0F; | ||
result.WriteByte((byte)hexChars[idx]); | ||
} | ||
else | ||
{ | ||
result.WriteByte((byte)c); | ||
} | ||
} | ||
|
||
static char[] hexChars = "0123456789ABCDEF".ToCharArray(); | ||
const string notEncoded = "!()*-._"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Collections" version="1.4.0" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.IO.Streams" version="1.1.27" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Text" version="1.2.22" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.System.Threading" version="1.1.8" targetFramework="netnano1.0" /> | ||
<package id="nanoFramework.TestFramework" version="2.0.60" targetFramework="netnano1.0" developmentDependency="true" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.