@@ -3,8 +3,6 @@ use fluent_uri::{ParseError as UriParseError, Uri};
33
44use crate :: { InfoHash , InfoHashError , TorrentID , Tracker , TrackerError } ;
55
6- use std:: string:: FromUtf8Error ;
7-
86/// Error occurred during parsing a [`MagnetLink`](crate::magnet::MagnetLink).
97#[ derive( Clone , Debug , PartialEq ) ]
108pub enum MagnetLinkError {
@@ -13,7 +11,7 @@ pub enum MagnetLinkError {
1311 /// The URI does not contain a query.
1412 InvalidURINoQuery ,
1513 /// The URI query contains non-UTF8 chars
16- InvalidURIQueryUnicode { source : FromUtf8Error } ,
14+ InvalidURIQueryUnicode ,
1715 /// The URI query contains a key without a value
1816 InvalidURIQueryEmptyValue { key : String } ,
1917 /// The URI query contains a non-urlencoded `?` beyond the query declaration
@@ -55,7 +53,7 @@ impl std::fmt::Display for MagnetLinkError {
5553 MagnetLinkError :: InvalidURIQueryEmptyValue { key } => {
5654 write ! ( f, "Invalid URI: query has key {key} with no value" )
5755 }
58- MagnetLinkError :: InvalidURIQueryUnicode { .. } => {
56+ MagnetLinkError :: InvalidURIQueryUnicode => {
5957 write ! ( f, "Invalid URI: the query part contains non-utf8 chars" )
6058 }
6159 MagnetLinkError :: InvalidURIQueryInterrogation => {
@@ -105,18 +103,11 @@ impl<Input> From<(UriParseError, Input)> for MagnetLinkError {
105103 }
106104}
107105
108- impl From < FromUtf8Error > for MagnetLinkError {
109- fn from ( e : FromUtf8Error ) -> MagnetLinkError {
110- MagnetLinkError :: InvalidURIQueryUnicode { source : e }
111- }
112- }
113-
114106impl std:: error:: Error for MagnetLinkError {
115107 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
116108 match self {
117109 MagnetLinkError :: InvalidURI { source } => Some ( source) ,
118110 MagnetLinkError :: InvalidHash { source } => Some ( source) ,
119- MagnetLinkError :: InvalidURIQueryUnicode { source } => Some ( source) ,
120111 MagnetLinkError :: InvalidTracker { source, .. } => Some ( source) ,
121112 _ => None ,
122113 }
@@ -210,17 +201,21 @@ impl MagnetLink {
210201 }
211202 name = val
212203 . decode ( )
213- . into_string ( ) ?
204+ . to_string ( )
205+ . map_err ( |_| MagnetLinkError :: InvalidURIQueryUnicode ) ?
214206 // fluent_uri explicitly does not decode U+002B (`+`) as a space
215207 . replace ( '+' , " " )
216208 . to_owned ( ) ;
217209 }
218210 "tr" => {
219- let tracker_uri = val. decode ( ) . into_string ( ) ?. into_owned ( ) ;
220- trackers. push ( Tracker :: new ( tracker_uri. as_str ( ) ) . map_err ( |e| {
211+ let tracker_uri = val
212+ . decode ( )
213+ . to_string ( )
214+ . map_err ( |_| MagnetLinkError :: InvalidURIQueryUnicode ) ?;
215+ trackers. push ( Tracker :: new ( & tracker_uri) . map_err ( |e| {
221216 MagnetLinkError :: InvalidTracker {
222217 source : e,
223- tracker : tracker_uri,
218+ tracker : tracker_uri. to_string ( ) ,
224219 }
225220 } ) ?) ;
226221 }
0 commit comments