Fix URL relativization so that links on Wikipedia work

This commit is contained in:
Patrick Walton 2013-06-11 11:15:45 -07:00
parent f3ad95fa01
commit 1aa8d6437d

View file

@ -30,10 +30,13 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
} else { } else {
let current_url = current_url.get(); let current_url = current_url.get();
debug!("make_url: current_url: %?", current_url); debug!("make_url: current_url: %?", current_url);
if current_url.path.is_empty() || current_url.path.ends_with("/") { if str_url.starts_with("//") {
current_url.scheme + "://" + current_url.host + "/" + str_url
} else if str_url.starts_with("//") {
current_url.scheme + ":" + str_url current_url.scheme + ":" + str_url
} else if current_url.path.is_empty() ||
str_url.starts_with("/") {
current_url.scheme + "://" +
current_url.host + "/" +
str_url.trim_left_chars([ '/' ])
} else { } else {
let mut path = ~[]; let mut path = ~[];
for str::each_split_char(current_url.path, '/') |p| { for str::each_split_char(current_url.path, '/') |p| {