Skip to content

Commit 7753ba9

Browse files
committed
deps: Update to fluent_uri v0.4
1 parent 8618ae7 commit 7753ba9

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sha1 = "0.10"
2525
sha256 = "1.5"
2626
rustc-hex = "2.1"
2727
serde = { version = "1", features = [ "derive" ] }
28-
fluent-uri = { git = "https://github.com/yescallop/fluent-uri-rs", rev = "5ad3b65", features = [ "serde" ] }
28+
fluent-uri = "0.4"
2929

3030
[dev-dependencies]
3131
serde_json = "1"

src/magnet.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use fluent_uri::{ParseError as UriParseError, Uri};
33

44
use 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)]
108
pub 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-
114106
impl 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

Comments
 (0)