std::net::url - fix to_str to work with authorityless urls, add test
This commit is contained in:
parent
21187206c3
commit
8e3105b6db
1 changed files with 16 additions and 6 deletions
|
@ -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,9 +662,8 @@ fn to_str(url: url) -> ~str {
|
|||
};
|
||||
|
||||
return str::concat(~[copy url.scheme,
|
||||
~"://",
|
||||
user,
|
||||
copy url.host,
|
||||
~":",
|
||||
authority,
|
||||
copy url.path,
|
||||
query,
|
||||
fragment]);
|
||||
|
@ -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(~"") == ~"";
|
||||
|
|
Loading…
Reference in a new issue