Skip to content

Commit e2c6c2c

Browse files
authored
fix: canonicalize_port should use url::quirks::set_port (#59)
1 parent 50b1c99 commit e2c6c2c

File tree

2 files changed

+145
-50
lines changed

2 files changed

+145
-50
lines changed

src/canonicalize_and_process.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ pub fn canonicalize_port(
7373
if let Some("") = protocol {
7474
protocol = None;
7575
}
76-
let port = value
77-
.parse::<u16>()
78-
.map_err(|_| Error::Url(url::ParseError::InvalidPort))?;
7976
// Note: this unwrap is safe, because the protocol was previously parsed to be
8077
// valid.
8178
let mut url =
8279
url::Url::parse(&format!("{}://dummy.test", protocol.unwrap_or("dummy")))
8380
.unwrap();
84-
url.set_port(Some(port)).unwrap(); // TODO: dont unwrap, instead ParseError
81+
url::quirks::set_port(&mut url, value)
82+
.map_err(|_| Error::Url(url::ParseError::InvalidPort))?;
8583
Ok(url::quirks::port(&url).to_string())
8684
}
8785

0 commit comments

Comments
 (0)