Skip to content

Commit 3fe1c70

Browse files
committed
std: Some fixes to url parsing
1 parent dbf5871 commit 3fe1c70

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/libstd/net_url.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,17 @@ fn get_authority(rawurl: ~str) ->
489489
end = i;
490490
}
491491
492+
let end = end; // make end immutable so it can be captured
493+
494+
let host_is_end_plus_one = || {
495+
end+1 == len
496+
&& !['?', '#', '/'].contains(rawurl[end] as char)
497+
};
498+
492499
// finish up
493500
match st {
494501
start {
495-
if end+1 == len {
502+
if host_is_end_plus_one() {
496503
host = str::slice(rawurl, begin, end+1);
497504
} else {
498505
host = str::slice(rawurl, begin, end);
@@ -516,7 +523,7 @@ fn get_authority(rawurl: ~str) ->
516523
}
517524
}
518525
519-
let rest = if end+1 == len { ~"" }
526+
let rest = if host_is_end_plus_one() { ~"" }
520527
else { str::slice(rawurl, end, len) };
521528
return result::ok((userinfo, host, port, rest));
522529
}
@@ -779,6 +786,15 @@ mod tests {
779786
assert option::unwrap(copy u.fragment) == ~"something";
780787
}
781788
789+
#[test]
790+
fn test_url_parse_host_slash() {
791+
let urlstr = ~"http://0.42.42.42/";
792+
let url = from_str(urlstr).get();
793+
#debug("url: %?", url);
794+
assert url.host == ~"0.42.42.42";
795+
assert url.path == ~"/";
796+
}
797+
782798
#[test]
783799
fn test_no_scheme() {
784800
assert result::is_err(get_scheme(~"noschemehere.html"));

0 commit comments

Comments
 (0)