Skip to content

Commit 8e3105b

Browse files
Daniel Pattersonbrson
authored andcommitted
std::net::url - fix to_str to work with authorityless urls, add test
1 parent 2118720 commit 8e3105b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/libstd/net_url.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,11 @@ fn to_str(url: url) -> ~str {
644644
} else {
645645
~""
646646
};
647+
let authority = if str::len(url.host) != 0 {
648+
str::concat(~[~"//", user, copy url.host])
649+
} else {
650+
~""
651+
};
647652
let query = if url.query.len() == 0 {
648653
~""
649654
} else {
@@ -657,12 +662,11 @@ fn to_str(url: url) -> ~str {
657662
};
658663

659664
return str::concat(~[copy url.scheme,
660-
~"://",
661-
user,
662-
copy url.host,
663-
copy url.path,
664-
query,
665-
fragment]);
665+
~":",
666+
authority,
667+
copy url.path,
668+
query,
669+
fragment]);
666670
}
667671

668672
impl of to_str::to_str for url {
@@ -849,6 +853,12 @@ mod tests {
849853
.get().second() == ~"#&+";
850854
}
851855
856+
#[test]
857+
fn test_url_without_authority() {
858+
let url = ~"mailto:test@email.com";
859+
assert to_str(result::unwrap(from_str(url))) == url;
860+
}
861+
852862
#[test]
853863
fn test_encode() {
854864
assert encode(~"") == ~"";

0 commit comments

Comments
 (0)