Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to rust-url 1.0 #9840

Merged
merged 6 commits into from Apr 23, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -97,4 +97,4 @@ rand = "0.3"
serde = "0.7"
serde_macros = "0.7"
time = "0.1.17"
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}
@@ -1932,7 +1932,7 @@ impl<LTF: LayoutThreadFactory, STF: ScriptThreadFactory> Constellation<LTF, STF>

let event_info = self.pipelines.get(&pipeline_id).and_then(|pipeline| {
pipeline.parent_info.map(|(containing_pipeline_id, subpage_id)| {
(containing_pipeline_id, subpage_id, pipeline.url.serialize())
(containing_pipeline_id, subpage_id, pipeline.url.to_string())
})
});

@@ -24,7 +24,7 @@ path = "../plugins"
git = "https://github.com/servo/ipc-channel"

[dependencies]
hyper = { version = "0.8", features = [ "serde-serialization" ] }
hyper = { version = "0.9", features = [ "serde-serialization" ] }
serde = "0.7"
serde_json = "0.7"
serde_macros = "0.7"
@@ -312,7 +312,7 @@ impl NetworkEventActor {
}

pub fn add_request(&mut self, request: DevtoolsHttpRequest) {
self.request.url = request.url.serialize();
self.request.url = request.url.as_str().to_owned();
self.request.method = request.method.clone();
self.request.headers = request.headers.clone();
self.request.body = request.body;
@@ -285,7 +285,7 @@ fn run_server(sender: Sender<DevtoolsControlMsg>,
let tab = TabActor {
name: actors.new_name("tab"),
title: String::from(title),
url: url.serialize(),
url: url.into_string(),
console: console.name(),
inspector: inspector.name(),
timeline: timeline.name(),
@@ -20,10 +20,10 @@ path = "../plugins"
[dependencies]
heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
hyper = { version = "0.8", features = [ "serde-serialization" ] }
hyper = { version = "0.9", features = [ "serde-serialization" ] }
time = "0.1"
bitflags = "0.3"
serde = "0.7"
serde_macros = "0.7"
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}

@@ -30,7 +30,7 @@ smallvec = "0.1"
string_cache = {version = "0.2.12", features = ["heap_size"]}
time = "0.1.12"
unicode-script = { version = "0.1", features = ["harfbuzz"] }
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}

[dependencies.plugins]
path = "../plugins"
@@ -79,4 +79,4 @@ string_cache = {version = "0.2.12", features = ["heap_size"]}
time = "0.1"
unicode-bidi = "0.2"
unicode-script = { version = "0.1", features = ["harfbuzz"] }
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}
@@ -1002,7 +1002,7 @@ impl LayoutThread {
let document = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap();

debug!("layout: received layout request for: {}", self.url.borrow().serialize());
debug!("layout: received layout request for: {}", *self.url.borrow());

let mut rw_data = possibly_locked_rw_data.lock();

@@ -1048,8 +1048,7 @@ impl LayoutThread {
Some(x) => x,
};

debug!("layout: received layout request for: {}",
self.url.borrow().serialize());
debug!("layout: received layout request for: {}", *self.url.borrow());
if log_enabled!(log::LogLevel::Debug) {
node.dump();
}
@@ -1463,7 +1462,7 @@ impl LayoutThread {
/// Returns profiling information which is passed to the time profiler.
fn profiler_metadata(&self) -> Option<TimerMetadata> {
Some(TimerMetadata {
url: self.url.borrow().serialize(),
url: self.url.borrow().to_string(),
iframe: if self.is_iframe {
TimerMetadataFrameType::IFrame
} else {
@@ -35,4 +35,4 @@ git = "https://github.com/servo/webrender_traits"
[dependencies]
serde = "0.7"
serde_macros = "0.7"
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}
@@ -30,8 +30,8 @@ cssparser = {version = "0.5.4", features = ["heap_size", "serde-serialization"]}
euclid = {version = "0.6.4", features = ["plugins"]}
heapsize = "0.3.0"
heapsize_plugin = "0.1.2"
hyper = { version = "0.8", features = [ "serde-serialization" ] }
hyper = { version = "0.9", features = [ "serde-serialization" ] }
rustc-serialize = "0.3.4"
serde = "0.7"
serde_macros = "0.7"
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size"]}
@@ -35,19 +35,20 @@ git = "https://github.com/servo/webrender_traits"
[dependencies]
cookie = "0.2"
flate2 = "0.2.0"
hyper = { version = "0.8", features = [ "serde-serialization" ] }
hyper = { version = "0.9", features = [ "serde-serialization" ] }
immeta = "0.3.1"
log = "0.3.5"
matches = "0.1"
mime = "0.2.0"
mime_guess = "1.6.0"
openssl = "0.7.6"
rustc-serialize = "0.3"
threadpool = "1.0"
time = "0.1.17"
unicase = "1.4.0"
url = {version = "0.5.7", features = ["heap_size"]}
url = {version = "1.0.0", features = ["heap_size", "rustc-serialize"]}
uuid = { version = "0.2", features = ["v4"] }
websocket = "0.16.1"
websocket = "0.17"

[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]
tinyfiledialogs = {git = "https://github.com/jdm/tinyfiledialogs"}
@@ -27,8 +27,7 @@ pub fn factory(mut load_data: LoadData,
classifier: Arc<MIMEClassifier>,
cancel_listener: CancellationListener) {
let url = load_data.url.clone();
let non_relative_scheme_data = url.non_relative_scheme_data().unwrap();
match non_relative_scheme_data {
match url.path() {
"blank" => {
let metadata = Metadata {
final_url: load_data.url,
@@ -49,7 +48,7 @@ pub fn factory(mut load_data: LoadData,
}
"crash" => panic!("Loading the about:crash URL."),
"failure" | "not-found" =>
url_from_non_relative_scheme(&mut load_data, &(non_relative_scheme_data.to_owned() + ".html")),
url_from_non_relative_scheme(&mut load_data, &(url.path().to_owned() + ".html")),
"sslfail" => url_from_non_relative_scheme(&mut load_data, "badcert.html"),
_ => {
send_error(load_data.url, NetworkError::Internal("Unknown about: URL.".to_owned()), start_chan);
@@ -6,27 +6,33 @@ use file_loader;
use mime_classifier::MIMEClassifier;
use net_traits::{LoadConsumer, LoadData, NetworkError};
use resource_thread::{CancellationListener, send_error};
use std::path::Path;
use std::fs::canonicalize;
use std::sync::Arc;
use url::Url;
use url::percent_encoding::percent_decode;
use util::resource_files::resources_dir_path;

pub fn resolve_chrome_url(url: &Url) -> Result<Url, ()> {
assert_eq!(url.scheme, "chrome");
// Skip the initial //
let non_relative_scheme_data = &url.non_relative_scheme_data().unwrap()[2..];
let relative_path = Path::new(non_relative_scheme_data);
// Don't allow chrome URLs access to files outside of the resources directory.
if non_relative_scheme_data.find("..").is_some() ||
relative_path.is_absolute() ||
relative_path.has_root() {
return Err(());
assert_eq!(url.scheme(), "chrome");
if url.host_str() != Some("resources") {
return Err(())
}
let resources = canonicalize(resources_dir_path())
.expect("Error canonicalizing path to the resources directory");
let mut path = resources.clone();
for segment in url.path_segments().unwrap() {
match percent_decode(segment.as_bytes()).decode_utf8() {
// Check ".." to prevent access to files outside of the resources directory.
Ok(segment) => path.push(&*segment),
_ => return Err(())
}
}
match canonicalize(path) {
Ok(ref path) if path.starts_with(&resources) && path.exists() => {
Ok(Url::from_file_path(path).unwrap())
}
_ => Err(())
}

let mut path = resources_dir_path();
path.push(non_relative_scheme_data);
assert!(path.exists());
return Ok(Url::from_file_path(&*path).unwrap());
}

pub fn factory(mut load_data: LoadData,
@@ -40,7 +40,7 @@ impl Cookie {
_ => (false, None)
};

let url_host = request.host().map_or("".to_owned(), |host| host.serialize());
let url_host = request.host_str().unwrap_or("").to_owned();

// Step 4
let mut domain = cookie.domain.clone().unwrap_or("".to_owned());
@@ -68,9 +68,7 @@ impl Cookie {
// Step 7
let mut path = cookie.path.unwrap_or("".to_owned());
if path.chars().next() != Some('/') {
let url_path = request.serialize_path();
let url_path = url_path.as_ref().map(|path| &**path);
path = Cookie::default_path(url_path.unwrap_or("")).to_owned();
path = Cookie::default_path(request.path()).to_owned();
}
cookie.path = Some(path);

@@ -147,26 +145,26 @@ impl Cookie {

// http://tools.ietf.org/html/rfc6265#section-5.4 step 1
pub fn appropriate_for_url(&self, url: &Url, source: CookieSource) -> bool {
let domain = url.host().map(|host| host.serialize());
let domain = url.host_str();
if self.host_only {
if self.cookie.domain != domain {
if self.cookie.domain.as_ref().map(String::as_str) != domain {
return false;
}
} else {
if let (Some(ref domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) {
if let (Some(domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) {
if !Cookie::domain_match(domain, cookie_domain) {
return false;
}
}
}

if let (Some(ref path), &Some(ref cookie_path)) = (url.serialize_path(), &self.cookie.path) {
if !Cookie::path_match(path, cookie_path) {
if let Some(ref cookie_path) = self.cookie.path {
if !Cookie::path_match(url.path(), cookie_path) {
return false;
}
}

if self.cookie.secure && url.scheme != "https" {
if self.cookie.secure && url.scheme() != "https" {
return false;
}
if self.cookie.httponly && source == CookieSource::NonHTTP {
@@ -10,9 +10,8 @@ use net_traits::{LoadData, Metadata, NetworkError};
use resource_thread::{CancellationListener, send_error, start_sending_sniffed_opt};
use rustc_serialize::base64::FromBase64;
use std::sync::Arc;
use url::SchemeData;
use url::Url;
use url::percent_encoding::percent_decode;
use url::{Position, Url};

pub fn factory(load_data: LoadData,
senders: LoadConsumer,
@@ -33,58 +32,42 @@ pub enum DecodeError {
pub type DecodeData = (Mime, Vec<u8>);

pub fn decode(url: &Url) -> Result<DecodeData, DecodeError> {
assert!(&*url.scheme == "data");
assert!(url.scheme() == "data");
// Split out content type and data.
let mut scheme_data = match url.scheme_data {
SchemeData::NonRelative(ref scheme_data) => scheme_data.clone(),
_ => panic!("Expected a non-relative scheme URL."),
};
match url.query {
Some(ref query) => {
scheme_data.push_str("?");
scheme_data.push_str(query);
},
None => ()
}
let parts: Vec<&str> = scheme_data.splitn(2, ',').collect();
let parts: Vec<&str> = url[Position::BeforePath..Position::AfterQuery].splitn(2, ',').collect();
if parts.len() != 2 {
return Err(DecodeError::InvalidDataUri);
}

// ";base64" must come at the end of the content type, per RFC 2397.
// rust-http will fail to parse it because there's no =value part.
let mut is_base64 = false;
let mut ct_str = parts[0].to_owned();
if ct_str.ends_with(";base64") {
is_base64 = true;
let end_index = ct_str.len() - 7;
ct_str.truncate(end_index);
}
if ct_str.starts_with(";charset=") {
ct_str = format!("text/plain{}", ct_str);
let mut ct_str = parts[0];
let is_base64 = ct_str.ends_with(";base64");
if is_base64 {
ct_str = &ct_str[..ct_str.len() - ";base64".len()];
}
let ct_str = if ct_str.starts_with(";charset=") {
format!("text/plain{}", ct_str)
} else {
ct_str.to_owned()
};

// Parse the content type using rust-http.
// FIXME: this can go into an infinite loop! (rust-http #25)
let mut content_type: Option<Mime> = ct_str.parse().ok();
if content_type == None {
content_type = Some(Mime(TopLevel::Text, SubLevel::Plain,
vec!((Attr::Charset, Value::Ext("US-ASCII".to_owned())))));
}
let content_type = ct_str.parse().unwrap_or_else(|_| {
Mime(TopLevel::Text, SubLevel::Plain,
vec![(Attr::Charset, Value::Ext("US-ASCII".to_owned()))])
});

let bytes = percent_decode(parts[1].as_bytes());
let bytes = if is_base64 {
let mut bytes = percent_decode(parts[1].as_bytes()).collect::<Vec<_>>();
if is_base64 {
// FIXME(#2909): It’s unclear what to do with non-alphabet characters,
// but Acid 3 apparently depends on spaces being ignored.
let bytes = bytes.into_iter().filter(|&b| b != ' ' as u8).collect::<Vec<u8>>();
bytes = bytes.into_iter().filter(|&b| b != ' ' as u8).collect::<Vec<u8>>();
match bytes.from_base64() {
Err(..) => return Err(DecodeError::NonBase64DataUri),
Ok(data) => data,
Ok(data) => bytes = data,
}
} else {
bytes
};
Ok((content_type.unwrap(), bytes))
}
Ok((content_type, bytes))
}

pub fn load(load_data: LoadData,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.