Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 5767306

Browse files
committed
#547 Remove '+' replacement from request cookies.
1 parent 7ebd87a commit 5767306

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/Microsoft.AspNetCore.Http/Internal/RequestCookieCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public static RequestCookieCollection Parse(IList<string> values)
7979
for (var i = 0; i < cookies.Count; i++)
8080
{
8181
var cookie = cookies[i];
82-
var name = Uri.UnescapeDataString(cookie.Name.Replace('+', ' '));
83-
var value = Uri.UnescapeDataString(cookie.Value.Replace('+', ' '));
82+
var name = Uri.UnescapeDataString(cookie.Name);
83+
var value = Uri.UnescapeDataString(cookie.Value);
8484
store[name] = value;
8585
}
8686

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Linq;
5+
using Microsoft.AspNetCore.Http.Internal;
6+
using Microsoft.Extensions.Primitives;
7+
using Xunit;
8+
9+
namespace Microsoft.AspNetCore.Http.Tests
10+
{
11+
public class RequestCookiesCollectionTests
12+
{
13+
public static TheoryData UnEscapesKeyValues_Data
14+
{
15+
get
16+
{
17+
// key, value, expected
18+
return new TheoryData<string, string, string>
19+
{
20+
{ "key=value", "key", "value" },
21+
{ "key%2C=%21value", "key,", "!value" },
22+
{ "ke%23y%2C=val%5Eue", "ke#y,", "val^ue" },
23+
{ "key=value", "key", "value" },
24+
{ "key%2C=%21value", "key,", "!value" },
25+
{ "ke%23y%2C=val%5Eue", "ke#y,", "val^ue" },
26+
{ "base64=QUI%2BREU%2FRw%3D%3D", "base64", "QUI+REU/Rw==" },
27+
{ "base64=QUI+REU/Rw==", "base64", "QUI+REU/Rw==" },
28+
};
29+
}
30+
}
31+
32+
[Theory]
33+
[MemberData(nameof(UnEscapesKeyValues_Data))]
34+
public void UnEscapesKeyValues(
35+
string input,
36+
string expectedKey,
37+
string expectedValue)
38+
{
39+
var cookies = RequestCookieCollection.Parse(new StringValues(input));
40+
41+
Assert.Equal(1, cookies.Count);
42+
Assert.Equal(expectedKey, cookies.Keys.Single());
43+
Assert.Equal(expectedValue, cookies[expectedKey]);
44+
}
45+
}
46+
}

test/Microsoft.AspNetCore.Http.Tests/ResponseCookiesTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static TheoryData EscapesKeyValuesBeforeSettingCookieData
7474
{ "key", "value", _builderPool, "key=value" },
7575
{ "key,", "!value", _builderPool, "key%2C=%21value" },
7676
{ "ke#y,", "val^ue", _builderPool, "ke%23y%2C=val%5Eue" },
77+
{ "base64", "QUI+REU/Rw==", _builderPool, "base64=QUI%2BREU%2FRw%3D%3D" },
7778
};
7879
}
7980
}

0 commit comments

Comments
 (0)