diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 90c5e037e4d6..d046dec52259 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -644,6 +644,11 @@ fn to_str(url: url) -> ~str { } else { ~"" }; + let authority = if str::len(url.host) != 0 { + str::concat(~[~"//", user, copy url.host]) + } else { + ~"" + }; let query = if url.query.len() == 0 { ~"" } else { @@ -657,12 +662,11 @@ fn to_str(url: url) -> ~str { }; return str::concat(~[copy url.scheme, - ~"://", - user, - copy url.host, - copy url.path, - query, - fragment]); + ~":", + authority, + copy url.path, + query, + fragment]); } impl of to_str::to_str for url { @@ -849,6 +853,12 @@ mod tests { .get().second() == ~"#&+"; } + #[test] + fn test_url_without_authority() { + let url = ~"mailto:test@email.com"; + assert to_str(result::unwrap(from_str(url))) == url; + } + #[test] fn test_encode() { assert encode(~"") == ~"";