Skip to content

Commit a1848bc

Browse files
committed
auto merge of #9927 : chris-morgan/rust/fix-url-to_str-so-it-includes-the-port, r=huonw
Fixes #9451. Fixes chris-morgan/rust-http#16.
2 parents 3f240fe + 1093730 commit a1848bc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libextra/url.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,13 @@ pub fn to_str(url: &Url) -> ~str {
671671
};
672672

673673
let authority = if url.host.is_empty() {
674+
// If port is Some, we're in a nonsensical situation. Too bad.
674675
~""
675676
} else {
676-
format!("//{}{}", user, url.host)
677+
match url.port {
678+
Some(ref port) => format!("//{}{}:{}", user, url.host, *port),
679+
None => format!("//{}{}", user, url.host),
680+
}
677681
};
678682

679683
let query = if url.query.is_empty() {
@@ -895,6 +899,12 @@ mod tests {
895899
assert_eq!(from_str(url).unwrap().to_str(), url);
896900
}
897901

902+
#[test]
903+
fn test_url_with_port_parse_and_format() {
904+
let url = ~"http://rust-lang.org:80/doc";
905+
assert_eq!(from_str(url).unwrap().to_str(), url);
906+
}
907+
898908
#[test]
899909
fn test_scheme_host_only_url_parse_and_format() {
900910
let url = ~"http://rust-lang.org";

0 commit comments

Comments
 (0)