From 8e3105b6db6eb30a95061b56e78581dae0a98996 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Wed, 1 Aug 2012 00:40:38 -0400 Subject: [PATCH] std::net::url - fix to_str to work with authorityless urls, add test --- src/libstd/net_url.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 90c5e037e4d..d046dec5225 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(~"") == ~"";