std: Some fixes to url parsing
This commit is contained in:
parent
dbf58716df
commit
3fe1c7071d
@ -489,10 +489,17 @@ fn get_authority(rawurl: ~str) ->
|
|||||||
end = i;
|
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
|
// finish up
|
||||||
match st {
|
match st {
|
||||||
start {
|
start {
|
||||||
if end+1 == len {
|
if host_is_end_plus_one() {
|
||||||
host = str::slice(rawurl, begin, end+1);
|
host = str::slice(rawurl, begin, end+1);
|
||||||
} else {
|
} else {
|
||||||
host = str::slice(rawurl, begin, end);
|
host = str::slice(rawurl, begin, end);
|
||||||
@ -516,7 +523,7 @@ fn get_authority(rawurl: ~str) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rest = if end+1 == len { ~"" }
|
let rest = if host_is_end_plus_one() { ~"" }
|
||||||
else { str::slice(rawurl, end, len) };
|
else { str::slice(rawurl, end, len) };
|
||||||
return result::ok((userinfo, host, port, rest));
|
return result::ok((userinfo, host, port, rest));
|
||||||
}
|
}
|
||||||
@ -779,6 +786,15 @@ mod tests {
|
|||||||
assert option::unwrap(copy u.fragment) == ~"something";
|
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]
|
#[test]
|
||||||
fn test_no_scheme() {
|
fn test_no_scheme() {
|
||||||
assert result::is_err(get_scheme(~"noschemehere.html"));
|
assert result::is_err(get_scheme(~"noschemehere.html"));
|
||||||
|
Loading…
Reference in New Issue
Block a user