std::net::url - fix to_str to work with authorityless urls, add test

This commit is contained in:
Daniel Patterson 2012-08-01 00:40:38 -04:00 committed by Brian Anderson
parent 21187206c3
commit 8e3105b6db

View file

@ -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(~"") == ~"";