Add tests for double-encoded URLs to both UrlDecode() methods (dotnet/corefx#37881)
authorWilliam Godbe <wigodbe@microsoft.com>
Fri, 31 May 2019 18:48:31 +0000 (11:48 -0700)
committerGitHub <noreply@github.com>
Fri, 31 May 2019 18:48:31 +0000 (11:48 -0700)
* Add tests for double-encoded URLs to both UrlDecode() methods

* Make test cases more clear

Commit migrated from https://github.com/dotnet/corefx/commit/b2fd315c40330e09d34d269792884f6544ab3fe6

src/libraries/System.Runtime.Extensions/tests/System/Net/WebUtility.cs
src/libraries/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs

index ba82125..2f992e6 100644 (file)
@@ -155,6 +155,11 @@ namespace System.Net.Tests
             yield return Tuple.Create("%1g", "%1g");
             yield return Tuple.Create("%G1", "%G1");
             yield return Tuple.Create("%1G", "%1G");
+
+            // The "Baz" portion of "http://example.net/Baz" has been double-encoded - one iteration of UrlDecode() should produce a once-encoded string.
+            yield return Tuple.Create("http://example.net/%2542%2561%257A", "http://example.net/%42%61%7A");
+            // The second iteration should return the original string
+            yield return Tuple.Create("http://example.net/%42%61%7A", "http://example.net/Baz");
         }
 
         public static IEnumerable<Tuple<string, string>> UrlEncode_SharedTestData()
index 42f5b1e..c1eca07 100644 (file)
@@ -462,7 +462,11 @@ namespace System.Web.Tests
                 new object[] { "http://example.net/\uFFFD", "http://example.net/\uD800" },
                 new object[] { "http://example.net/\uFFFDa", "http://example.net/\uD800a" },
                 new object[] { "http://example.net/\uFFFD", "http://example.net/\uDC00" },
-                new object[] { "http://example.net/\uFFFDa", "http://example.net/\uDC00a" }
+                new object[] { "http://example.net/\uFFFDa", "http://example.net/\uDC00a" },
+                // The "Baz" portion of "http://example.net/Baz" has been double-encoded - one iteration of UrlDecode() should produce a once-encoded string.
+                new object[] { "http://example.net/%42%61%7A", "http://example.net/%2542%2561%257A"},
+                // The second iteration should return the original string
+                new object[] { "http://example.net/Baz", "http://example.net/%42%61%7A"}
             };
 
         public static IEnumerable<object[]> UrlDecodeDataToBytes =>