@@ -20,12 +20,12 @@ public static bool TryParse(string? queryString, bool caseIgnore, [NotNullWhen(t
20
20
{
21
21
if ( queryString is null )
22
22
{
23
- nameValueCollection = default ;
23
+ nameValueCollection = null ;
24
24
return false ;
25
25
}
26
26
27
27
var parts = queryString !
28
- . Split ( new [ ] { "&" } , StringSplitOptions . RemoveEmptyEntries )
28
+ . Split ( [ "&" ] , StringSplitOptions . RemoveEmptyEntries )
29
29
. Select ( parameter => parameter . Split ( '=' ) )
30
30
. Distinct ( ) ;
31
31
@@ -50,18 +50,6 @@ public static IDictionary<string, WireMockList<string>> Parse(string? queryStrin
50
50
51
51
var queryParameterMultipleValueSupport = support ?? QueryParameterMultipleValueSupport . All ;
52
52
53
- string [ ] JoinParts ( string [ ] parts )
54
- {
55
- if ( parts . Length > 1 )
56
- {
57
- return queryParameterMultipleValueSupport . HasFlag ( QueryParameterMultipleValueSupport . Comma ) ?
58
- parts [ 1 ] . Split ( new [ ] { "," } , StringSplitOptions . RemoveEmptyEntries ) : // Support "?key=1,2"
59
- new [ ] { parts [ 1 ] } ;
60
- }
61
-
62
- return new string [ 0 ] ;
63
- }
64
-
65
53
var splitOn = new List < string > ( ) ;
66
54
if ( queryParameterMultipleValueSupport . HasFlag ( QueryParameterMultipleValueSupport . Ampersand ) )
67
55
{
@@ -74,8 +62,24 @@ string[] JoinParts(string[] parts)
74
62
75
63
return queryString ! . TrimStart ( '?' )
76
64
. Split ( splitOn . ToArray ( ) , StringSplitOptions . RemoveEmptyEntries )
77
- . Select ( parameter => parameter . Split ( new [ ] { '=' } , 2 , StringSplitOptions . RemoveEmptyEntries ) )
78
- . GroupBy ( parts => parts [ 0 ] , JoinParts )
79
- . ToDictionary ( grouping => grouping . Key , grouping => new WireMockList < string > ( grouping . SelectMany ( x => x ) . Select ( WebUtility . UrlDecode ) ) ) ;
65
+ . Select ( parameter => new { hasEqualSign = parameter . Contains ( '=' ) , parts = parameter . Split ( [ '=' ] , 2 , StringSplitOptions . RemoveEmptyEntries ) } )
66
+ . GroupBy ( x => x . parts [ 0 ] , y => JoinParts ( y . hasEqualSign , y . parts ) )
67
+ . ToDictionary
68
+ (
69
+ grouping => grouping . Key ,
70
+ grouping => new WireMockList < string > ( grouping . SelectMany ( x => x ) . Select ( WebUtility . UrlDecode ) . OfType < string > ( ) )
71
+ ) ;
72
+
73
+ string [ ] JoinParts ( bool hasEqualSign , string [ ] parts )
74
+ {
75
+ if ( parts . Length > 1 )
76
+ {
77
+ return queryParameterMultipleValueSupport . HasFlag ( QueryParameterMultipleValueSupport . Comma ) ?
78
+ parts [ 1 ] . Split ( [ "," ] , StringSplitOptions . RemoveEmptyEntries ) : // Support "?key=1,2"
79
+ [ parts [ 1 ] ] ;
80
+ }
81
+
82
+ return hasEqualSign ? [ string . Empty ] : [ ] ; // Return empty string if equal sign with no value (#1247)
83
+ }
80
84
}
81
85
}
0 commit comments