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