<!-- Please describe your changes on the following line: --> This PR removes the `util` crate. * Replaced the `spawn_named` and `clamp` functions by appropriate uses of `std:🧵:Builder::spawn`, `std::cmp::min` and `std::cmp::max`. * Moved `opts`, `prefs` and `resource_files` into a new `config` crate. * Moved `remutex` and `geometry` into their own crates. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not require tests because they are refactorings <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4eb653817f87e5fb47de34356f558eb76ecbca9f
32 lines
1.2 KiB
Rust
32 lines
1.2 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use servo_config::resource_files::resources_dir_path;
|
|
use servo_url::ServoUrl;
|
|
use std::fs::canonicalize;
|
|
use url::percent_encoding::percent_decode;
|
|
|
|
pub fn resolve_chrome_url(url: &ServoUrl) -> Result<ServoUrl, ()> {
|
|
assert_eq!(url.scheme(), "chrome");
|
|
if url.host_str() != Some("resources") {
|
|
return Err(())
|
|
}
|
|
let resources = canonicalize(resources_dir_path().expect("Error finding resource folder"))
|
|
.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(ServoUrl::from_file_path(path).unwrap())
|
|
}
|
|
_ => Err(())
|
|
}
|
|
}
|