Try to parse command line argument as file names

… when parsing as an absolute URL (without a base) fails.

Previously, arguments were parsed as URLs with the current working directory
converted to an URL and used as the base URL. This mostly worked for
relative filenames, except that `?` and `#` had a special meaning
and needed to be percent-encoded.

Fix #3340.
This commit is contained in:
Simon Sapin 2014-09-16 14:31:45 +01:00
parent 7a5f15f137
commit 11135d75cb
3 changed files with 10 additions and 8 deletions

View file

@ -57,8 +57,6 @@ use std::os;
use std::task::TaskBuilder;
#[cfg(not(test), target_os="android")]
use std::string;
#[cfg(not(test))]
use url::{Url, UrlParser};
#[cfg(not(test), target_os="android")]
#[no_mangle]
@ -125,12 +123,15 @@ pub fn run(opts: opts::Opts) {
font_cache_task,
time_profiler_chan_clone);
let base_url = Url::from_directory_path(&os::getcwd()).unwrap();
let mut url_parser = UrlParser::new();
let url_parser = url_parser.base_url(&base_url);
// Send the URL command to the constellation.
for url in opts.urls.iter() {
let url = url_parser.parse(url.as_slice()).ok().expect("URL parsing failed");
let cwd = os::getcwd();
for &url in opts.urls.iter() {
let url = match url::Url::parse(url.as_slice()) {
Ok(url) => url,
Err(url::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&cwd.join(url)).unwrap(),
Err(_) => fail!("URL parsing failed"),
};
let ConstellationChan(ref chan) = constellation_chan;
chan.send(InitLoadUrlMsg(url));

View file

@ -1,6 +1,7 @@
== basic_width_px.html basic_width_em.html
== br.html br-ref.html
== hello_a.html hello_b.html
# `?` and `#` in the name is a test for https://github.com/servo/servo/issues/3340
== hello_a?foo#bar.html hello_b.html
== margin_a.html margin_b.html
== root_pseudo_a.html root_pseudo_b.html
== first_child_pseudo_a.html first_child_pseudo_b.html