@@ -331,8 +331,8 @@ impl Router {
331331 method : & Method ,
332332 path : & str ,
333333 ) -> Option < ( Arc < HandlerFn > , HashMap < String , String > ) > {
334- let decoded = match urlencoding :: decode ( path) {
335- Ok ( cow ) => cow . into_owned ( ) ,
334+ let decoded = match Url :: parse ( & format ! ( "http://localhost{}" , path) ) {
335+ Ok ( url ) => url . path ( ) . to_string ( ) ,
336336 Err ( _) => return None ,
337337 } ;
338338
@@ -884,58 +884,6 @@ impl fmt::Debug for IpcHttpServer {
884884 }
885885}
886886
887- pub mod urlencoding {
888- use std:: borrow:: Cow ;
889-
890- #[ derive( Debug ) ]
891- pub struct DecodeError ;
892-
893- impl std:: fmt:: Display for DecodeError {
894- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
895- write ! ( f, "Invalid URL encoding" )
896- }
897- }
898-
899- impl std:: error:: Error for DecodeError { }
900-
901- pub fn decode ( input : & str ) -> Result < Cow < ' _ , str > , DecodeError > {
902- if !input. contains ( '%' ) && !input. contains ( '+' ) {
903- return Ok ( Cow :: Borrowed ( input) ) ;
904- }
905-
906- let mut result = Vec :: new ( ) ;
907- let bytes = input. as_bytes ( ) ;
908- let mut i = 0 ;
909-
910- while i < bytes. len ( ) {
911- match bytes[ i] {
912- b'%' => {
913- if i + 2 < bytes. len ( ) {
914- let hex_str =
915- std:: str:: from_utf8 ( & bytes[ i + 1 ..i + 3 ] ) . map_err ( |_| DecodeError ) ?;
916- let byte = u8:: from_str_radix ( hex_str, 16 ) . map_err ( |_| DecodeError ) ?;
917- result. push ( byte) ;
918- i += 3 ;
919- } else {
920- return Err ( DecodeError ) ;
921- }
922- }
923- b'+' => {
924- result. push ( b' ' ) ;
925- i += 1 ;
926- }
927- byte => {
928- result. push ( byte) ;
929- i += 1 ;
930- }
931- }
932- }
933-
934- let decoded_str = String :: from_utf8 ( result) . map_err ( |_| DecodeError ) ?;
935- Ok ( Cow :: Owned ( decoded_str) )
936- }
937- }
938-
939887#[ cfg( test) ]
940888mod tests {
941889 use super :: * ;
0 commit comments