std: Some fixes to url parsing
This commit is contained in:
parent
dbf58716df
commit
3fe1c7071d
@ -489,10 +489,17 @@ enum input {
|
||||
end = i;
|
||||
}
|
||||
|
||||
let end = end; // make end immutable so it can be captured
|
||||
|
||||
let host_is_end_plus_one = || {
|
||||
end+1 == len
|
||||
&& !['?', '#', '/'].contains(rawurl[end] as char)
|
||||
};
|
||||
|
||||
// finish up
|
||||
match st {
|
||||
start {
|
||||
if end+1 == len {
|
||||
if host_is_end_plus_one() {
|
||||
host = str::slice(rawurl, begin, end+1);
|
||||
} else {
|
||||
host = str::slice(rawurl, begin, end);
|
||||
@ -516,7 +523,7 @@ enum input {
|
||||
}
|
||||
}
|
||||
|
||||
let rest = if end+1 == len { ~"" }
|
||||
let rest = if host_is_end_plus_one() { ~"" }
|
||||
else { str::slice(rawurl, end, len) };
|
||||
return result::ok((userinfo, host, port, rest));
|
||||
}
|
||||
@ -779,6 +786,15 @@ fn test_url_parse() {
|
||||
assert option::unwrap(copy u.fragment) == ~"something";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_url_parse_host_slash() {
|
||||
let urlstr = ~"http://0.42.42.42/";
|
||||
let url = from_str(urlstr).get();
|
||||
#debug("url: %?", url);
|
||||
assert url.host == ~"0.42.42.42";
|
||||
assert url.path == ~"/";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_scheme() {
|
||||
assert result::is_err(get_scheme(~"noschemehere.html"));
|
||||
|
Loading…
Reference in New Issue
Block a user