3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
using Microsoft . Extensions . Primitives ;
7
8
using Xunit ;
8
9
@@ -15,7 +16,9 @@ public class HeaderDictionaryTests
15
16
new [ ] { "Value1" , "Value2" , "Value3" , "Value4" } ,
16
17
new [ ] { "Value1" , "" , "Value3" , "Value4" } ,
17
18
new [ ] { "Value1" , "" , "" , "Value4" } ,
18
- new [ ] { "" , "" , "" , "" }
19
+ new [ ] { "Value1" , "" , null , "Value4" } ,
20
+ new [ ] { "" , "" , "" , "" } ,
21
+ new [ ] { "" , null , "" , null } ,
19
22
} ;
20
23
21
24
[ Fact ]
@@ -37,7 +40,7 @@ public void PropertiesAreAccessible()
37
40
38
41
[ Theory ]
39
42
[ MemberData ( nameof ( HeaderSegmentData ) ) ]
40
- public void EmptyHeaderSegmentsAreParsable ( IEnumerable < string > segments )
43
+ public void EmptyHeaderSegmentsAreIgnored ( IEnumerable < string > segments )
41
44
{
42
45
var header = string . Join ( "," , segments ) ;
43
46
@@ -48,8 +51,22 @@ public void EmptyHeaderSegmentsAreParsable(IEnumerable<string> segments)
48
51
} ) ;
49
52
50
53
var result = headers . GetCommaSeparatedValues ( "Header1" ) ;
54
+ var expectedResult = segments . Where ( s => ! string . IsNullOrEmpty ( s ) ) ;
51
55
52
- Assert . Equal ( segments , result ) ;
56
+ Assert . Equal ( expectedResult , result ) ;
57
+ }
58
+
59
+ [ Fact ]
60
+ public void EmtpyQuotedHeaderSegmentsAreIgnored ( )
61
+ {
62
+ var headers = new HeaderDictionary (
63
+ new Dictionary < string , StringValues > ( StringComparer . OrdinalIgnoreCase )
64
+ {
65
+ { "Header1" , "Value1,\" \" ,,Value2" } ,
66
+ } ) ;
67
+
68
+ var result = headers . GetCommaSeparatedValues ( "Header1" ) ;
69
+ Assert . Equal ( new [ ] { "Value1" , "Value2" } , result ) ;
53
70
}
54
71
}
55
72
}
0 commit comments