From 11135d75cb4dc8352df1743b9ceadc8e6ec1876c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 16 Sep 2014 14:31:45 +0100 Subject: [PATCH] Try to parse command line argument as file names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … 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. --- src/lib.rs | 15 ++++++++------- tests/ref/basic.list | 3 ++- tests/ref/{hello_a.html => hello_a?foo#bar.html} | 0 3 files changed, 10 insertions(+), 8 deletions(-) rename tests/ref/{hello_a.html => hello_a?foo#bar.html} (100%) diff --git a/src/lib.rs b/src/lib.rs index bb01ad7c739..a00d935ade3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)); diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 9cdcdb108fb..82d2b826099 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -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 diff --git a/tests/ref/hello_a.html b/tests/ref/hello_a?foo#bar.html similarity index 100% rename from tests/ref/hello_a.html rename to tests/ref/hello_a?foo#bar.html