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

Make chrome: URLs have a "host".

  • Loading branch information
SimonSapin committed Apr 23, 2016
commit 374679852c07ed24f3591da94745038362df86ae
@@ -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()) {
@@ -42,7 +42,7 @@ lazy_static! {
Ok(res) => {
let ua_stylesheet = Stylesheet::from_bytes(
&res,
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
Url::parse(&format!("chrome://resources/{:?}", filename)).unwrap(),
None,
None,
Origin::UserAgent,
@@ -69,7 +69,7 @@ lazy_static! {
Ok(res) => {
Stylesheet::from_bytes(
&res,
Url::parse("chrome:///quirks-mode.css").unwrap(),
Url::parse("chrome://resources/quirks-mode.css").unwrap(),
None,
None,
Origin::UserAgent,
@@ -3,6 +3,6 @@
<title>Certificate error</title>
</head>
<body>
<img src="chrome:/badcert.jpg">
<img src="chrome://resources/badcert.jpg">
</body>
</html>
@@ -7,40 +7,46 @@ use url::Url;

#[test]
fn test_relative() {
let url = Url::parse("chrome:/../something").unwrap();
let url = Url::parse("chrome://resources/../something").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}

#[test]
fn test_relative_2() {
let url = Url::parse("chrome:/subdir/../something").unwrap();
let url = Url::parse("chrome://resources/subdir/../something").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}

#[test]
#[cfg(not(target_os = "windows"))]
fn test_absolute() {
let url = Url::parse("chrome:/etc/passwd").unwrap();
let url = Url::parse("chrome://resources/etc/passwd").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}

#[test]
#[cfg(target_os = "windows")]
fn test_absolute_2() {
let url = Url::parse("chrome:/C:\\Windows").unwrap();
let url = Url::parse("chrome://resources/C:\\Windows").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}

#[test]
#[cfg(target_os = "windows")]
fn test_absolute_3() {
let url = Url::parse("chrome:/\\\\server/C$").unwrap();
let url = Url::parse("chrome://resources/\\\\server/C$").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}

#[test]
fn test_valid() {
let url = Url::parse("chrome:/badcert.jpg").unwrap();
let url = Url::parse("chrome://resources/badcert.jpg").unwrap();
let resolved = resolve_chrome_url(&url).unwrap();
assert_eq!(resolved.scheme(), "file");
}

#[test]
fn test_incorrect_host() {
let url = Url::parse("chrome://not-resources/badcert.jpg").unwrap();
assert!(resolve_chrome_url(&url).is_err());
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.