Auto merge of #7610 - servo:filename-parsing, r=saneyuki

Replace reftest with a problematic file name with a unit test.

Fix #7609, "error: unable to create file tests/ref/hello_a?foo#bar.html (Invalid argument)" during git checkout on Windows.

Behavior change: passing an nonexistent file name on the command line now shows a blank page (like network errors) rather than exit with an error message.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7610)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-12 09:10:37 -06:00
commit 815e981c69
6 changed files with 53 additions and 30 deletions

View file

@ -14,7 +14,7 @@ use prefs;
use std::cmp;
use std::default::Default;
use std::env;
use std::fs::{File, PathExt};
use std::fs::File;
use std::io::{self, Read, Write};
use std::path::Path;
use std::process;
@ -485,18 +485,8 @@ pub fn from_cmdline_args(args: &[String]) {
print_usage(app_name, &opts);
args_fail("servo asks that you provide a URL")
} else {
let ref url = opt_match.free[0];
match Url::parse(url) {
Ok(url) => url,
Err(url::ParseError::RelativeUrlWithoutBase) => {
if Path::new(url).exists() {
Url::from_file_path(&*cwd.join(url)).unwrap()
} else {
args_fail(&format!("File not found: {}", url))
}
}
Err(_) => panic!("URL parsing failed"),
}
parse_url_or_filename(&cwd, &opt_match.free[0])
.unwrap_or_else(|()| args_fail("URL parsing failed"))
};
let tile_size: usize = match opt_match.opt_str("s") {
@ -663,3 +653,13 @@ pub fn set_defaults(opts: Opts) {
pub fn get() -> &'static Opts {
&OPTIONS
}
pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result<Url, ()> {
match Url::parse(input) {
Ok(url) => Ok(url),
Err(url::ParseError::RelativeUrlWithoutBase) => {
Ok(Url::from_file_path(&*cwd.join(input)).unwrap())
}
Err(_) => Err(()),
}
}