mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Make chrome: URLs have a "host".
This commit is contained in:
parent
7375e2cedd
commit
374679852c
4 changed files with 20 additions and 10 deletions
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue