File tree 2 files changed +18
-15
lines changed
2 files changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -758,8 +758,8 @@ pub struct Location {
758
758
759
759
/// The parsed "query" part of "www.example.com/index.html?query#fragment".
760
760
///
761
- /// "foo=42 &bar%20" is parsed as `{"foo ": "42", "bar ": "" }`
762
- pub query_map : std:: collections:: BTreeMap < String , String > ,
761
+ /// "foo=hello &bar%20&foo=world " is parsed as `{"bar ": [""], "foo ": ["hello", "world"] }`
762
+ pub query_map : std:: collections:: BTreeMap < String , Vec < String > > ,
763
763
764
764
/// `location.origin`
765
765
///
Original file line number Diff line number Diff line change @@ -117,21 +117,24 @@ pub fn web_location() -> epi::Location {
117
117
}
118
118
119
119
/// query is percent-encoded
120
- fn parse_query_map ( query : & str ) -> BTreeMap < String , String > {
121
- query
122
- . split ( '&' )
123
- . filter_map ( |pair| {
124
- if pair. is_empty ( ) {
125
- None
120
+ fn parse_query_map ( query : & str ) -> BTreeMap < String , Vec < String > > {
121
+ let mut map: BTreeMap < String , Vec < String > > = Default :: default ( ) ;
122
+
123
+ for pair in query. split ( '&' ) {
124
+ if !pair. is_empty ( ) {
125
+ if let Some ( ( key, value) ) = pair. split_once ( '=' ) {
126
+ map. entry ( percent_decode ( key) )
127
+ . or_default ( )
128
+ . push ( percent_decode ( value) ) ;
126
129
} else {
127
- Some ( if let Some ( ( key, value) ) = pair. split_once ( '=' ) {
128
- ( percent_decode ( key) , percent_decode ( value) )
129
- } else {
130
- ( percent_decode ( pair) , String :: new ( ) )
131
- } )
130
+ map. entry ( percent_decode ( pair) )
131
+ . or_default ( )
132
+ . push ( String :: new ( ) ) ;
132
133
}
133
- } )
134
- . collect ( )
134
+ }
135
+ }
136
+
137
+ map
135
138
}
136
139
137
140
// TODO(emilk): this test is never acgtually run, because this whole module is wasm32 only 🤦♂️
You can’t perform that action at this time.
0 commit comments