Make chrome: URLs have a "host".

This commit is contained in:
Simon Sapin 2016-04-23 01:16:29 +02:00
parent 7375e2cedd
commit 374679852c
4 changed files with 20 additions and 10 deletions

View file

@ -8,14 +8,18 @@ use net_traits::{LoadConsumer, LoadData, NetworkError};
use resource_thread::{CancellationListener, send_error};
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");
if url.host_str() != Some("resources") {
return Err(())
}
let resources = resources_dir_path();
let mut path = resources.clone();
for segment in url.path_segments().unwrap() {
path.push(segment)
path.push(&*try!(percent_decode(segment.as_bytes()).decode_utf8().map_err(|_| ())))
}
// Don't allow chrome URLs access to files outside of the resources directory.
if !(path.starts_with(resources) && path.exists()) {