Skip to content

Commit f5d0fba

Browse files
committed
Added Url Decode test
Added a comprehensive UrlDecode test that checks characters from 0 to 55295 or U+D7FF to ensure correct decoding.
1 parent b1ee2f4 commit f5d0fba

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Tests/HttpUnitTests/HttpUtilityTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ public void UrlDecodeNoThrow()
2626
Assert.AreEqual(str, HttpUtility.UrlDecode(str));
2727
}
2828

29+
[TestMethod]
30+
public void UrlDecodeTest()
31+
{
32+
for (char c = char.MinValue; c < '\uD800'; c++)
33+
{
34+
byte[] bIn;
35+
bIn = Encoding.UTF8.GetBytes(c.ToString());
36+
MemoryStream encodedValueBytes = new MemoryStream();
37+
38+
// build expected result for UrlEncode
39+
for (int i = 0; i < bIn.Length; i++)
40+
{
41+
UrlEncodeChar((char)bIn[i], encodedValueBytes, false);
42+
}
43+
44+
byte[] bOut = encodedValueBytes.ToArray();
45+
string encodedValue = Encoding.UTF8.GetString(bOut, 0, bOut.Length);
46+
47+
string decodedValue = HttpUtility.UrlDecode(encodedValue);
48+
49+
Assert.AreEqual(c.ToString(), decodedValue,
50+
$"Expecting UrlEncode of '{c}' ({(int)c}) as [{c}] got {decodedValue}");
51+
}
52+
}
53+
2954
[TestMethod]
3055
public void UrlEncodeTest()
3156
{

0 commit comments

Comments
 (0)