aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2013-12-09 22:16:10 -0800
committerbors-servo <release+servo@mozilla.com>2013-12-09 22:16:10 -0800
commit4b3defb2825289ff47d099c87887ba990aa2bffe (patch)
treecc25273db3eadef62920273ea4a546229988c2f8 /src
parent794ea62ed9ef1b999d45f256c731795a4e5ba512 (diff)
parent2d3fa10923acac68d792e0487c185c64bdb369bb (diff)
downloadservo-4b3defb2825289ff47d099c87887ba990aa2bffe.tar.gz
servo-4b3defb2825289ff47d099c87887ba990aa2bffe.zip
auto merge of #1353 : dhedlund/servo/resource_port_and_user, r=pcwalton
User credentials and port were not being preserved when pre-fetching path-based resources. For example, consider the following HTML: ```html <html> <body> <img src="logo.png" /> </body> ``` Running the following command would try to fetch the image from `http://localhost/my-site/logo.png` and crash the browser with ConnectionRefused error: ``` $ ./servo http://foo:bar@localhost:8080/my-site/ task '<unnamed>' failed at 'Unhandled condition: io_error: rt::io::IoError{kind: ConnectionRefused, desc: "connection refused", detail: None}', /home/daniel/Programming/servo/src/compiler/rust/src/libstd/condition.rs:131 ... ``` This should now be fixed.
Diffstat (limited to 'src')
-rw-r--r--src/components/util/url.rs61
1 files changed, 43 insertions, 18 deletions
diff --git a/src/components/util/url.rs b/src/components/util/url.rs
index aeb5245f9fa..1e492fa08bb 100644
--- a/src/components/util/url.rs
+++ b/src/components/util/url.rs
@@ -35,26 +35,22 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
} else {
let current_url = current_url.unwrap();
debug!("make_url: current_url: {:?}", current_url);
+
+ let mut new_url = current_url.clone();
+ new_url.query = ~[];
+ new_url.fragment = None;
+
if str_url.starts_with("//") {
- 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(&'/')
+ new_url.scheme + ":" + str_url
+ } else if current_url.path.is_empty() || str_url.starts_with("/") {
+ new_url.path = ~"/";
+ new_url.to_str() + str_url.trim_left_chars(&'/')
} else if str_url.starts_with("#") {
- current_url.scheme + "://" + current_url.host + current_url.path + str_url
- } else {
- let mut path = ~[];
- for p in current_url.path.split_iter('/') {
- path.push(p.to_str());
- }
- let path = path.init();
- let mut path = path.iter().map(|x| (*x).clone()).collect::<~[~str]>();
- path.push(str_url);
- let path = path.connect("/");
-
- current_url.scheme + "://" + current_url.host + path
+ new_url.to_str() + str_url
+ } else { // relative path
+ let base_path = current_url.path.trim_right_chars(&|c: char| c != '/');
+ new_url.path = base_path.to_owned();
+ new_url.to_str() + str_url
}
}
},
@@ -159,6 +155,35 @@ mod make_url_tests {
assert!(new_url.path == ~"/index.html");
assert!(new_url.fragment == Some(~"top"));
}
+
+ #[test]
+ fn should_create_url_based_on_old_url_6() {
+ use extra::url::UserInfo;
+
+ let old_str = ~"http://foo:bar@example.com:8080/index.html";
+ let old_url = make_url(old_str, None);
+ let new_str = ~"#top";
+ let new_url = make_url(new_str, Some(old_url));
+
+ assert!(new_url.scheme == ~"http");
+ assert!(new_url.user == Some(UserInfo { user: ~"foo", pass: Some(~"bar") }));
+ assert!(new_url.host == ~"example.com");
+ assert!(new_url.port == Some(~"8080"));
+ assert!(new_url.path == ~"/index.html");
+ assert!(new_url.fragment == Some(~"top"));
+ }
+
+ #[test]
+ fn should_create_url_based_on_old_url_7() {
+ let old_str = ~"https://example.com/snarf/index.html";
+ let old_url = make_url(old_str, None);
+ let new_str = ~"//example.com/crumpet.html";
+ let new_url = make_url(new_str, Some(old_url));
+ assert!(new_url.scheme == ~"https");
+ assert!(new_url.host == ~"example.com");
+ assert!(new_url.path == ~"/crumpet.html");
+ }
+
}
pub type UrlMap<T> = HashMap<Url, T>;