From 903e8cc3b9092cb2b838e13b2da9a1f878fe95b0 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Fri, 31 May 2019 11:48:31 -0700 Subject: [PATCH] Add tests for double-encoded URLs to both UrlDecode() methods (dotnet/corefx#37881) * 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 --- .../System.Runtime.Extensions/tests/System/Net/WebUtility.cs | 5 +++++ .../System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Net/WebUtility.cs b/src/libraries/System.Runtime.Extensions/tests/System/Net/WebUtility.cs index ba82125..2f992e6 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Net/WebUtility.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Net/WebUtility.cs @@ -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> UrlEncode_SharedTestData() diff --git a/src/libraries/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs b/src/libraries/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs index 42f5b1e..c1eca07 100644 --- a/src/libraries/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs +++ b/src/libraries/System.Web.HttpUtility/tests/HttpUtility/HttpUtilityTest.cs @@ -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 UrlDecodeDataToBytes => -- 2.7.4