diff --git a/Cargo.toml b/Cargo.toml
index 9e1ecfd..f25abff 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,7 +25,7 @@ sha1 = "0.10"
sha256 = "1.5"
rustc-hex = "2.1"
serde = { version = "1", features = [ "derive" ] }
-fluent-uri = { git = "https://github.com/yescallop/fluent-uri-rs", rev = "5ad3b65", features = [ "serde" ] }
+fluent-uri = "0.4"
[dev-dependencies]
serde_json = "1"
diff --git a/src/magnet.rs b/src/magnet.rs
index c84bcdf..bfa4b62 100644
--- a/src/magnet.rs
+++ b/src/magnet.rs
@@ -3,8 +3,6 @@ use fluent_uri::{ParseError as UriParseError, Uri};
use crate::{InfoHash, InfoHashError, TorrentID, Tracker, TrackerError};
-use std::string::FromUtf8Error;
-
/// Error occurred during parsing a [`MagnetLink`](crate::magnet::MagnetLink).
#[derive(Clone, Debug, PartialEq)]
pub enum MagnetLinkError {
@@ -13,7 +11,7 @@ pub enum MagnetLinkError {
/// The URI does not contain a query.
InvalidURINoQuery,
/// The URI query contains non-UTF8 chars
- InvalidURIQueryUnicode { source: FromUtf8Error },
+ InvalidURIQueryUnicode,
/// The URI query contains a key without a value
InvalidURIQueryEmptyValue { key: String },
/// The URI query contains a non-urlencoded `?` beyond the query declaration
@@ -55,7 +53,7 @@ impl std::fmt::Display for MagnetLinkError {
MagnetLinkError::InvalidURIQueryEmptyValue { key } => {
write!(f, "Invalid URI: query has key {key} with no value")
}
- MagnetLinkError::InvalidURIQueryUnicode { .. } => {
+ MagnetLinkError::InvalidURIQueryUnicode => {
write!(f, "Invalid URI: the query part contains non-utf8 chars")
}
MagnetLinkError::InvalidURIQueryInterrogation => {
@@ -105,18 +103,11 @@ impl From<(UriParseError, Input)> for MagnetLinkError {
}
}
-impl From for MagnetLinkError {
- fn from(e: FromUtf8Error) -> MagnetLinkError {
- MagnetLinkError::InvalidURIQueryUnicode { source: e }
- }
-}
-
impl std::error::Error for MagnetLinkError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
MagnetLinkError::InvalidURI { source } => Some(source),
MagnetLinkError::InvalidHash { source } => Some(source),
- MagnetLinkError::InvalidURIQueryUnicode { source } => Some(source),
MagnetLinkError::InvalidTracker { source, .. } => Some(source),
_ => None,
}
@@ -210,17 +201,21 @@ impl MagnetLink {
}
name = val
.decode()
- .into_string()?
+ .to_string()
+ .map_err(|_| MagnetLinkError::InvalidURIQueryUnicode)?
// fluent_uri explicitly does not decode U+002B (`+`) as a space
.replace('+', " ")
.to_owned();
}
"tr" => {
- let tracker_uri = val.decode().into_string()?.into_owned();
- trackers.push(Tracker::new(tracker_uri.as_str()).map_err(|e| {
+ let tracker_uri = val
+ .decode()
+ .to_string()
+ .map_err(|_| MagnetLinkError::InvalidURIQueryUnicode)?;
+ trackers.push(Tracker::new(&tracker_uri).map_err(|e| {
MagnetLinkError::InvalidTracker {
source: e,
- tracker: tracker_uri,
+ tracker: tracker_uri.to_string(),
}
})?);
}