Skip to content

Commit 5ddf2fa

Browse files
committed
Unescape query parameter name
1 parent b1480ca commit 5ddf2fa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Http/WebUtilities/src/QueryHelpers.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ public static Dictionary<string, StringValues> ParseQuery(string? queryString)
218218
{
219219
if (delimiterIndex > scanIndex)
220220
{
221-
accumulator.Append(queryString.Substring(scanIndex, delimiterIndex - scanIndex), string.Empty);
221+
string name = queryString.Substring(scanIndex, delimiterIndex - scanIndex);
222+
accumulator.Append(
223+
Uri.UnescapeDataString(name.Replace('+', ' ')),
224+
string.Empty);
222225
}
223226
}
224227
scanIndex = delimiterIndex + 1;

src/Http/WebUtilities/test/QueryHelpersTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public void ParseQueryWithEmptyKeyWorks()
5555
Assert.Equal(new[] { "value1", "" }, collection[""]);
5656
}
5757

58+
[Fact]
59+
public void ParseQueryWithEncodedKeyWorks()
60+
{
61+
var collection = QueryHelpers.ParseQuery("?fields%5BtodoItems%5D");
62+
Assert.Single(collection);
63+
Assert.Equal("", collection["fields[todoItems]"].FirstOrDefault());
64+
}
65+
5866
[Theory]
5967
[InlineData("?")]
6068
[InlineData("")]

0 commit comments

Comments
 (0)