diff options
| author | bors <bors@rust-lang.org> | 2013-10-18 07:21:25 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-10-18 07:21:25 -0700 |
| commit | a1848bc755411285afb15f2453df7567e10ebc04 (patch) | |
| tree | 2f445b7d53fb95a6ffbce39fba99a38892cf6c3f | |
| parent | 3f240fedecf84f9bb614c52f5cc1335057008749 (diff) | |
| parent | 1093730d721e64d71f0db18239714903d7f731b1 (diff) | |
| download | rust-a1848bc755411285afb15f2453df7567e10ebc04.tar.gz rust-a1848bc755411285afb15f2453df7567e10ebc04.zip | |
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.
| -rw-r--r-- | src/libextra/url.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libextra/url.rs b/src/libextra/url.rs index 2afc49df43a..e836d3b5270 100644 --- a/src/libextra/url.rs +++ b/src/libextra/url.rs @@ -671,9 +671,13 @@ pub fn to_str(url: &Url) -> ~str { }; let authority = if url.host.is_empty() { + // If port is Some, we're in a nonsensical situation. Too bad. ~"" } else { - format!("//{}{}", user, url.host) + match url.port { + Some(ref port) => format!("//{}{}:{}", user, url.host, *port), + None => format!("//{}{}", user, url.host), + } }; let query = if url.query.is_empty() { @@ -896,6 +900,12 @@ mod tests { } #[test] + fn test_url_with_port_parse_and_format() { + let url = ~"http://rust-lang.org:80/doc"; + assert_eq!(from_str(url).unwrap().to_str(), url); + } + + #[test] fn test_scheme_host_only_url_parse_and_format() { let url = ~"http://rust-lang.org"; assert_eq!(from_str(url).unwrap().to_str(), url); |
