1
- // Copyright (c) .NET Foundation. All rights reserved.
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
+ using System ;
4
5
using System . Linq ;
5
6
using Microsoft . AspNetCore . Http . Internal ;
6
7
using Microsoft . Extensions . Primitives ;
@@ -10,30 +11,32 @@ namespace Microsoft.AspNetCore.Http.Tests
10
11
{
11
12
public class RequestCookiesCollectionTests
12
13
{
13
- public static TheoryData UnEscapesKeyValues_Data
14
+ [ Theory ]
15
+ [ InlineData ( "key=value" , "key" , "value" ) ]
16
+ [ InlineData ( "__secure-key=value" , "__secure-key" , "value" ) ]
17
+ [ InlineData ( "key%2C=%21value" , "key," , "!value" ) ]
18
+ [ InlineData ( "ke%23y%2C=val%5Eue" , "ke#y," , "val^ue" ) ]
19
+ [ InlineData ( "base64=QUI%2BREU%2FRw%3D%3D" , "base64" , "QUI+REU/Rw==" ) ]
20
+ [ InlineData ( "base64=QUI+REU/Rw==" , "base64" , "QUI+REU/Rw==" ) ]
21
+ public void UnEscapesValues ( string input , string expectedKey , string expectedValue )
14
22
{
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
- { "base64=QUI%2BREU%2FRw%3D%3D" , "base64" , "QUI+REU/Rw==" } ,
24
- { "base64=QUI+REU/Rw==" , "base64" , "QUI+REU/Rw==" } ,
25
- } ;
26
- }
23
+ var cookies = RequestCookieCollection . Parse ( new StringValues ( input ) ) ;
24
+
25
+ Assert . Equal ( 1 , cookies . Count ) ;
26
+ Assert . Equal ( Uri . EscapeDataString ( expectedKey ) , cookies . Keys . Single ( ) ) ;
27
+ Assert . Equal ( expectedValue , cookies [ expectedKey ] ) ;
27
28
}
28
29
29
30
[ Theory ]
30
- [ MemberData ( nameof ( UnEscapesKeyValues_Data ) ) ]
31
- public void UnEscapesKeyValues (
32
- string input ,
33
- string expectedKey ,
34
- string expectedValue )
31
+ [ InlineData ( "key=value" , "key" , "value" ) ]
32
+ [ InlineData ( "__secure-key=value" , "__secure-key" , "value" ) ]
33
+ [ InlineData ( "key%2C=%21value" , "key," , "!value" ) ]
34
+ [ InlineData ( "ke%23y%2C=val%5Eue" , "ke#y," , "val^ue" ) ]
35
+ [ InlineData ( "base64=QUI%2BREU%2FRw%3D%3D" , "base64" , "QUI+REU/Rw==" ) ]
36
+ [ InlineData ( "base64=QUI+REU/Rw==" , "base64" , "QUI+REU/Rw==" ) ]
37
+ public void AppContextSwitchUnEscapesKeyValues ( string input , string expectedKey , string expectedValue )
35
38
{
36
- var cookies = RequestCookieCollection . Parse ( new StringValues ( input ) ) ;
39
+ var cookies = RequestCookieCollection . ParseInternal ( new StringValues ( input ) , enableCookieNameDecoding : true ) ;
37
40
38
41
Assert . Equal ( 1 , cookies . Count ) ;
39
42
Assert . Equal ( expectedKey , cookies . Keys . Single ( ) ) ;
0 commit comments