Skip to content

Fix extra::url::to_str to include the port. #9927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/libextra/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -895,6 +899,12 @@ mod tests {
assert_eq!(from_str(url).unwrap().to_str(), url);
}

#[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";
Expand Down