Skip to content

Commit 9c1bfd6

Browse files
author
Andrew Hall
committed
Add back UrlDecoderTests
1 parent 138491f commit 9c1bfd6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT license. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.AspNetCore.Razor.Test.Common;
6+
using Microsoft.AspNetCore.Razor.Utilities;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Microsoft.CodeAnalysis.Razor.Workspaces.Test.Utilities;
11+
12+
public class UrlDecoderTests(ITestOutputHelper testOutput) : ToolingTestBase(testOutput)
13+
{
14+
public static IEnumerable<object[]> UrlDecodeData =>
15+
new[]
16+
{
17+
new object[] { "http://127.0.0.1:8080/appDir/page.aspx?foo=bar", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%61r" },
18+
new object[] { "http://127.0.0.1:8080/appDir/page.aspx?foo=b%ar", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%%61r" },
19+
new object[] { "http://127.0.0.1:8080/app%Dir/page.aspx?foo=b%ar", "http://127.0.0.1:8080/app%Dir/page.aspx?foo=b%%61r" },
20+
new object[] { "http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r", "http://127.0.0.1:8080/app%%Dir/page.aspx?foo=b%%r" },
21+
new object[] { "http://127.0.0.1:8080/appDir/page.aspx?foo=ba%r", "http://127.0.0.1:8080/appDir/page.aspx?foo=b%61%r" },
22+
new object[] { "http://127.0.0.1:8080/appDir/page.aspx?foo=bar baz", "http://127.0.0.1:8080/appDir/page.aspx?foo=bar+baz" },
23+
new object[] { "http://example.net/\U00010000", "http://example.net/\U00010000" },
24+
new object[] { "http://example.net/\uD800", "http://example.net/\uD800" },
25+
new object[] { "http://example.net/\uD800a", "http://example.net/\uD800a" },
26+
// The "Baz" portion of "http://example.net/Baz" has been double-encoded - one iteration of UrlDecode() should produce a once-encoded string.
27+
new object[] { "http://example.net/%6A%6B%6C", "http://example.net/%256A%256B%256C"},
28+
// The second iteration should return the original string
29+
new object[] { "http://example.net/jkl", "http://example.net/%6A%6B%6C"},
30+
// This example uses lowercase hex characters
31+
new object[] { "http://example.net/jkl", "http://example.net/%6a%6b%6c"}
32+
};
33+
34+
[Theory]
35+
[MemberData(nameof(UrlDecodeData))]
36+
public void Decode(string decoded, string encoded)
37+
{
38+
Assert.Equal(UrlDecoder.Decode(encoded), decoded);
39+
}
40+
}

0 commit comments

Comments
 (0)