aboutsummaryrefslogtreecommitdiffstats
path: root/src/servo/util/url.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/servo/util/url.rs')
-rw-r--r--src/servo/util/url.rs56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/servo/util/url.rs b/src/servo/util/url.rs
index cbdbae33d98..f9148f9d296 100644
--- a/src/servo/util/url.rs
+++ b/src/servo/util/url.rs
@@ -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";
+}