mirror of
https://github.com/servo/servo.git
synced 2025-06-17 04:44:28 +00:00
Make relative hrefs work
This commit is contained in:
parent
633c013567
commit
c37528df7d
3 changed files with 59 additions and 5 deletions
|
@ -131,7 +131,7 @@ class Content<S:Sink send copy> {
|
|||
// Note: we can parse the next document in parallel
|
||||
// with any previous documents.
|
||||
let stream = spawn_html_lexer_task(copy url, self.resource_task);
|
||||
let (root, style_port, js_port) = build_dom(self.scope, stream);
|
||||
let (root, style_port, js_port) = build_dom(self.scope, stream, url);
|
||||
let css_rules = style_port.recv();
|
||||
let js_scripts = js_port.recv();
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ fn js_script_listener(to_parent : comm::chan<~[~[u8]]>, from_parent : comm::port
|
|||
}
|
||||
|
||||
#[warn(no_non_implicitly_copyable_typarams)]
|
||||
fn build_dom(scope: NodeScope, stream: comm::port<Token>) -> (Node, comm::port<Stylesheet>, comm::port<~[~[u8]]>) {
|
||||
fn build_dom(scope: NodeScope, stream: comm::port<Token>, url: url) -> (Node, comm::port<Stylesheet>, comm::port<~[~[u8]]>) {
|
||||
// The current reference node.
|
||||
let mut cur_node = scope.new_node(Element(ElementData(~"html", ~HTMLDivElement)));
|
||||
// We will spawn a separate task to parse any css that is
|
||||
|
@ -204,8 +204,8 @@ fn build_dom(scope: NodeScope, stream: comm::port<Token>) -> (Node, comm::port<S
|
|||
some(filename) {
|
||||
#debug["Linking to a css sheet named: %s", filename];
|
||||
// FIXME: Need to base the new url on the current url
|
||||
let url = make_url(filename, none);
|
||||
style_chan.send(File(url));
|
||||
let new_url = make_url(filename, some(url));
|
||||
style_chan.send(File(new_url));
|
||||
}
|
||||
none { /* fall through*/ }
|
||||
}
|
||||
|
|
|
@ -21,7 +21,17 @@ fn make_url(str_url: ~str, current_url: option<url>) -> url {
|
|||
// and build an absolute path with the cwd
|
||||
~"file://" + path::connect(os::getcwd(), str_url)
|
||||
} else {
|
||||
fail;//current_url.get().scheme + "://" + str_url
|
||||
let current_url = current_url.get();
|
||||
#debug("make_url: current_url: %?", current_url);
|
||||
if current_url.path.is_empty() || current_url.path.ends_with("/") {
|
||||
current_url.scheme + "://" + path::connect(current_url.host, str_url)
|
||||
} else {
|
||||
let path = path::split(current_url.path);
|
||||
let path = path.init();
|
||||
let path = path::connect_many(path + ~[str_url]);
|
||||
|
||||
current_url.scheme + "://" + path::connect(current_url.host, path)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -37,3 +47,47 @@ fn should_create_absolute_file_url_if_current_url_is_none_and_str_url_looks_file
|
|||
assert url.scheme == ~"file";
|
||||
assert url.path.contains(os::getcwd());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_create_url_based_on_old_url_1() {
|
||||
let old_str = ~"http://example.com";
|
||||
let old_url = make_url(old_str, none);
|
||||
let new_str = ~"index.html";
|
||||
let new_url = make_url(new_str, some(old_url));
|
||||
assert new_url.scheme == ~"http";
|
||||
assert new_url.host == ~"example.com";
|
||||
assert new_url.path == ~"/index.html";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_create_url_based_on_old_url_2() {
|
||||
let old_str = ~"http://example.com/";
|
||||
let old_url = make_url(old_str, none);
|
||||
let new_str = ~"index.html";
|
||||
let new_url = make_url(new_str, some(old_url));
|
||||
assert new_url.scheme == ~"http";
|
||||
assert new_url.host == ~"example.com";
|
||||
assert new_url.path == ~"/index.html";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_create_url_based_on_old_url_3() {
|
||||
let old_str = ~"http://example.com/index.html";
|
||||
let old_url = make_url(old_str, none);
|
||||
let new_str = ~"crumpet.html";
|
||||
let new_url = make_url(new_str, some(old_url));
|
||||
assert new_url.scheme == ~"http";
|
||||
assert new_url.host == ~"example.com";
|
||||
assert new_url.path == ~"/crumpet.html";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_create_url_based_on_old_url_4() {
|
||||
let old_str = ~"http://example.com/snarf/index.html";
|
||||
let old_url = make_url(old_str, none);
|
||||
let new_str = ~"crumpet.html";
|
||||
let new_url = make_url(new_str, some(old_url));
|
||||
assert new_url.scheme == ~"http";
|
||||
assert new_url.host == ~"example.com";
|
||||
assert new_url.path == ~"/snarf/crumpet.html";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue