diff options
| author | Daniel Patterson <dbp@riseup.net> | 2012-08-01 00:40:38 -0400 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-03 11:28:19 -0700 |
| commit | 8e3105b6db6eb30a95061b56e78581dae0a98996 (patch) | |
| tree | f22a8e0194911345132e4cbbd027ddb2c6297ec2 /src/libstd | |
| parent | 21187206c3521f10d91627771d682c513a4356dc (diff) | |
std::net::url - fix to_str to work with authorityless urls, add test
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net_url.rs | 22 |
1 files 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 { @@ -850,6 +854,12 @@ mod tests { } #[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(~"") == ~""; assert encode(~"http://example.com") == ~"http://example.com"; |
