@@ -124,17 +124,18 @@ pub fn render(
124124 query_and_params : & str ,
125125 split_odb : bool ,
126126) -> JoshResult < Option < ( String , std:: collections:: BTreeMap < String , String > ) > > {
127- let mut parameters = query_and_params. split ( '&' ) ;
128- let query = parameters
129- . next ( )
130- . ok_or_else ( || josh_error ( & format ! ( "invalid query {:?}" , query_and_params) ) ) ?;
131- let mut split = query. splitn ( 2 , '=' ) ;
132- let cmd = split
133- . next ( )
134- . ok_or_else ( || josh_error ( & format ! ( "invalid query {:?}" , query_and_params) ) ) ?;
135- let path = split
136- . next ( )
137- . ok_or_else ( || josh_error ( & format ! ( "invalid query {:?}" , query_and_params) ) ) ?;
127+ let params = form_urlencoded:: parse ( & query_and_params. as_bytes ( ) )
128+ . map ( |( x, y) | ( x. to_string ( ) , y. to_string ( ) ) )
129+ . collect :: < std:: collections:: BTreeMap < _ , _ > > ( ) ;
130+ let ( cmd, path) = if let Some ( path) = params. get ( "get" ) {
131+ ( "get" , path)
132+ } else if let Some ( path) = params. get ( "graphql" ) {
133+ ( "graphql" , path)
134+ } else if let Some ( path) = params. get ( "render" ) {
135+ ( "render" , path)
136+ } else {
137+ return Err ( josh_error ( "no command" ) ) ;
138+ } ;
138139
139140 let tree = transaction. repo ( ) . find_commit ( commit_id) ?. tree ( ) ?;
140141
@@ -146,18 +147,6 @@ pub fn render(
146147 }
147148 ) ;
148149
149- let mut params = std:: collections:: BTreeMap :: new ( ) ;
150- for p in parameters {
151- let mut split = p. splitn ( 2 , '=' ) ;
152- let name = split
153- . next ( )
154- . ok_or_else ( || josh_error ( & format ! ( "invalid query {:?}" , query_and_params) ) ) ?;
155- let value = split
156- . next ( )
157- . ok_or_else ( || josh_error ( & format ! ( "invalid query {:?}" , query_and_params) ) ) ?;
158- params. insert ( name. to_string ( ) , value. to_string ( ) ) ;
159- }
160-
161150 let template = if let Ok ( blob) = obj. peel_to_blob ( ) {
162151 let file = std:: str:: from_utf8 ( blob. content ( ) ) ?;
163152 if cmd == "get" {
0 commit comments