Auto merge of #9019 - magopian:9002-use-url.join, r=SimonSapin

Use Url.join instead of UrlParser.base_url(...).parse (#9002)

Fix issue #9002

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9019)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-12-19 01:58:56 +05:30
commit f9141ef2db
41 changed files with 58 additions and 64 deletions

View file

@ -78,7 +78,7 @@ gleam = "0.2"
euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"
[target.x86_64-apple-darwin.dependencies]
core-graphics = "0.2"

View file

@ -29,4 +29,4 @@ time = "0.1"
rustc-serialize = "0.3"
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"

View file

@ -26,5 +26,5 @@ rustc-serialize = "0.3"
bitflags = "0.3"
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"

View file

@ -25,7 +25,7 @@ smallvec = "0.1"
string_cache = "0.2"
time = "0.1.12"
unicode-script = { version = "0.1", features = ["harfbuzz"] }
url = "0.5"
url = "0.5.2"
servo-skia = "0.20130412.0"
[dependencies.plugins]

View file

@ -75,4 +75,4 @@ serde_json = "0.5"
time = "0.1"
unicode-bidi = "0.2"
unicode-script = { version = "0.1", features = ["harfbuzz"] }
url = "0.5"
url = "0.5.2"

View file

@ -32,4 +32,4 @@ git = "https://github.com/servo/ipc-channel"
euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"

View file

@ -33,7 +33,7 @@ rustc-serialize = "0.3.4"
euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"
[target.x86_64-apple-darwin.dependencies]
core-foundation = "0.2"

View file

@ -39,5 +39,5 @@ mime_guess = "1.1.1"
flate2 = "0.2.0"
uuid = "0.1.16"
euclid = {version = "0.4", features = ["plugins"]}
url = "0.5"
url = "0.5.2"
websocket = "0.14.0"

View file

@ -17,7 +17,7 @@ use std::ascii::AsciiExt;
use std::cell::RefCell;
use std::rc::Rc;
use std::str::FromStr;
use url::{Url, UrlParser};
use url::Url;
use util::task::spawn_named;
/// A [request context](https://fetch.spec.whatwg.org/#concept-request-context)
@ -367,7 +367,7 @@ impl Request {
_ => return Response::network_error(),
};
// Step 5
let location_url = UrlParser::new().base_url(self.url_list.last().unwrap()).parse(&*location);
let location_url = self.url_list.last().unwrap().join(&*location);
// Step 6
let location_url = match location_url {
Ok(ref url) if url.scheme == "data" => { return Response::network_error(); }

View file

@ -37,7 +37,7 @@ use std::error::Error;
use std::io::{self, Read, Write};
use std::sync::mpsc::Sender;
use std::sync::{Arc, RwLock};
use url::{Url, UrlParser};
use url::Url;
use util::resource_files::resources_dir_path;
use util::task::spawn_named;
use uuid;
@ -700,7 +700,7 @@ pub fn load<A>(load_data: LoadData,
}
}
let new_doc_url = match UrlParser::new().base_url(&doc_url).parse(&new_url) {
let new_doc_url = match doc_url.join(&new_url) {
Ok(u) => u,
Err(e) => {
return Err(LoadError::InvalidRedirect(doc_url, e.to_string()));

View file

@ -29,5 +29,5 @@ hyper = { version = "0.7", features = [ "serde-serialization" ] }
image = "0.5.0"
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"
websocket = "0.14.0"

View file

@ -17,7 +17,7 @@ branch = "servo"
optional = true
[dependencies]
url = "0.5"
url = "0.5.2"
[features]
default = []

View file

@ -87,5 +87,5 @@ rand = "0.3"
serde = "0.6"
caseless = "0.1.0"
image = "0.5.0"
url = "0.5"
url = "0.5.2"
ref_slice = "0.1.0"

View file

@ -81,7 +81,6 @@ use style::properties::longhands::{self, background_image, border_spacing, font_
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
use url::UrlParser;
use util::mem::HeapSizeOf;
use util::str::{DOMString, LengthOrPercentageOrAuto};
@ -1051,7 +1050,7 @@ impl Element {
let base = doc.url();
// https://html.spec.whatwg.org/multipage/#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(&base).parse(&url) {
match base.join(&url) {
Ok(parsed) => DOMString::from(parsed.serialize()),
Err(_) => DOMString::from(""),
}

View file

@ -25,7 +25,6 @@ use dom::virtualmethods::VirtualMethods;
use num::ToPrimitive;
use std::default::Default;
use string_cache::Atom;
use url::UrlParser;
use util::str::DOMString;
#[dom_struct]
@ -187,7 +186,7 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>) {
// Step 4-5.
let document = document_from_node(subject);
let url = match UrlParser::new().base_url(&document.url()).parse(&href) {
let url = match document.url().join(&href) {
Ok(url) => url,
Err(_) => return,
};

View file

@ -12,7 +12,7 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, document_from_node};
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use url::{Url, UrlParser};
use url::Url;
use util::str::DOMString;
#[dom_struct]
@ -42,7 +42,7 @@ impl HTMLBaseElement {
that have a base url.");
let document = document_from_node(self);
let base = document.fallback_base_url();
let parsed = UrlParser::new().base_url(&base).parse(&href.value());
let parsed = base.join(&href.value());
parsed.unwrap_or(base)
}

View file

@ -22,7 +22,7 @@ use script_traits::ScriptMsg as ConstellationMsg;
use std::rc::Rc;
use string_cache::Atom;
use time;
use url::{Url, UrlParser};
use url::Url;
use util::str::DOMString;
/// How long we should wait before performing the initial reflow after `<body>` is parsed, in
@ -157,7 +157,7 @@ impl VirtualMethods for HTMLBodyElement {
*self.background.borrow_mut() = mutation.new_value(attr).and_then(|value| {
let document = document_from_node(self);
let base = document.url();
UrlParser::new().base_url(&base).parse(&value).ok()
base.join(&value).ok()
});
true
},

View file

@ -35,7 +35,6 @@ use script_task::{MainThreadScriptMsg, ScriptChan};
use std::borrow::ToOwned;
use std::cell::Cell;
use string_cache::Atom;
use url::UrlParser;
use url::form_urlencoded::serialize;
use util::str::DOMString;
@ -200,7 +199,7 @@ impl HTMLFormElement {
action = DOMString::from(base.serialize());
}
// Step 9-11
let action_components = match UrlParser::new().base_url(base).parse(&action) {
let action_components = match base.join(&action) {
Ok(url) => url,
Err(_) => return
};

View file

@ -32,7 +32,7 @@ use script_traits::ScriptMsg as ConstellationMsg;
use std::ascii::AsciiExt;
use std::cell::Cell;
use string_cache::Atom;
use url::{Url, UrlParser};
use url::Url;
use util::prefs;
use util::str::DOMString;
use util::str::{self, LengthOrPercentageOrAuto};
@ -74,8 +74,7 @@ impl HTMLIFrameElement {
None
} else {
let window = window_from_node(self);
UrlParser::new().base_url(&window.get_url())
.parse(&url).ok()
window.get_url().join(&url).ok()
}
})
}

View file

@ -27,7 +27,7 @@ use script_task::ScriptTaskEventCategory::UpdateReplacedElement;
use script_task::{CommonScriptMsg, Runnable, ScriptChan};
use std::sync::Arc;
use string_cache::Atom;
use url::{Url, UrlParser};
use url::Url;
use util::str::DOMString;
#[dom_struct]
@ -101,7 +101,7 @@ impl HTMLImageElement {
*self.image.borrow_mut() = None;
}
Some((src, base_url)) => {
let img_url = UrlParser::new().base_url(&base_url).parse(&src);
let img_url = base_url.join(&src);
// FIXME: handle URL parse errors more gracefully.
let img_url = img_url.unwrap();
*self.url.borrow_mut() = Some(img_url.clone());

View file

@ -37,7 +37,7 @@ use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::media_queries::{MediaQueryList, parse_media_query_list};
use style::stylesheets::{Origin, Stylesheet};
use url::{Url, UrlParser};
use url::Url;
use util::str::{DOMString, HTML_SPACE_CHARACTERS};
no_jsmanaged_fields!(Stylesheet);
@ -182,7 +182,7 @@ impl HTMLLinkElement {
fn handle_stylesheet_url(&self, href: &str) {
let window = window_from_node(self);
let window = window.r();
match UrlParser::new().base_url(&window.get_url()).parse(href) {
match window.get_url().join(href) {
Ok(url) => {
let element = self.upcast::<Element>();
@ -232,7 +232,7 @@ impl HTMLLinkElement {
fn handle_favicon_url(&self, rel: &str, href: &str, sizes: &Option<String>) {
let window = window_from_node(self);
let window = window.r();
match UrlParser::new().base_url(&window.get_url()).parse(href) {
match window.get_url().join(href) {
Ok(url) => {
let ConstellationChan(ref chan) = window.constellation_chan();
let event = ConstellationMsg::NewFavicon(url.clone());

View file

@ -41,7 +41,7 @@ use std::cell::Cell;
use std::mem;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use url::{Url, UrlParser};
use url::Url;
use util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec};
#[dom_struct]
@ -263,7 +263,7 @@ impl HTMLScriptElement {
}
// Step 15.3
match UrlParser::new().base_url(&base_url).parse(&src) {
match base_url.join(&src) {
Err(_) => {
// Step 15.4
error!("error parsing URL for script {}", &**src);

View file

@ -10,7 +10,7 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::USVString;
use dom::urlhelper::UrlHelper;
use dom::window::Window;
use url::{Url, UrlParser};
use url::Url;
use util::str::DOMString;
#[dom_struct]
@ -51,7 +51,7 @@ impl LocationMethods for Location {
// TODO: per spec, we should use the _API base URL_ specified by the
// _entry settings object_.
let base_url = self.window.get_url();
if let Ok(url) = UrlParser::new().base_url(&base_url).parse(&url.0) {
if let Ok(url) = base_url.join(&url.0) {
self.window.load_url(url);
}
}
@ -98,7 +98,7 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-href
fn SetHref(&self, value: USVString) {
if let Ok(url) = UrlParser::new().base_url(&self.window.get_url()).parse(&value.0) {
if let Ok(url) = self.window.get_url().join(&value.0) {
self.window.load_url(url);
}
}

View file

@ -26,7 +26,6 @@ use js::jsapi::{JSAutoCompartment, JSAutoRequest};
use js::jsval::UndefinedValue;
use script_task::{Runnable, ScriptChan};
use std::sync::mpsc::{Sender, channel};
use url::UrlParser;
use util::str::DOMString;
pub type TrustedWorkerAddress = Trusted<Worker>;
@ -64,7 +63,7 @@ impl Worker {
// https://html.spec.whatwg.org/multipage/#dom-worker
pub fn Constructor(global: GlobalRef, script_url: DOMString) -> Fallible<Root<Worker>> {
// Step 2-4.
let worker_url = match UrlParser::new().base_url(&global.get_url()).parse(&script_url) {
let worker_url = match global.get_url().join(&script_url) {
Ok(url) => url,
Err(_) => return Err(Error::Syntax),
};

View file

@ -31,7 +31,7 @@ use std::default::Default;
use std::rc::Rc;
use std::sync::mpsc::Receiver;
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
use url::{Url, UrlParser};
use url::Url;
use util::str::DOMString;
#[derive(Copy, Clone, PartialEq)]
@ -195,8 +195,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
fn ImportScripts(&self, url_strings: Vec<DOMString>) -> ErrorResult {
let mut urls = Vec::with_capacity(url_strings.len());
for url in url_strings {
let url = UrlParser::new().base_url(&self.worker_url)
.parse(&url);
let url = self.worker_url.join(&url);
match url {
Ok(url) => urls.push(url),
Err(_) => return Err(Error::Syntax),

View file

@ -60,7 +60,7 @@ use std::sync::{Arc, Mutex};
use string_cache::Atom;
use time;
use timers::{ScheduledCallback, TimerHandle};
use url::{Url, UrlParser};
use url::Url;
use util::mem::HeapSizeOf;
use util::str::DOMString;
@ -326,7 +326,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
// Step 6
let base = self.global.root().r().get_url();
let parsed_url = match UrlParser::new().base_url(&base).parse(&url) {
let parsed_url = match base.join(&url) {
Ok(parsed) => parsed,
Err(_) => return Err(Error::Syntax) // Step 7
};
@ -1109,7 +1109,7 @@ impl XMLHttpRequest {
let doc = doc.r();
let docloader = DocumentLoader::new(&*doc.loader());
let base = self.global.root().r().get_url();
let parsed_url = match UrlParser::new().base_url(&base).parse(&self.ResponseURL()) {
let parsed_url = match base.join(&self.ResponseURL()) {
Ok(parsed) => Some(parsed),
Err(_) => None // Step 7
};

View file

@ -98,7 +98,7 @@ use std::sync::atomic::{Ordering, AtomicBool};
use std::sync::mpsc::{Receiver, Select, Sender, channel};
use std::sync::{Arc, Mutex};
use time::{Tm, now};
use url::{Url, UrlParser};
use url::Url;
use util::opts;
use util::str::DOMString;
use util::task;
@ -1840,7 +1840,7 @@ impl ScriptTask {
.and_then(|href| {
let value = href.value();
let url = document.url();
UrlParser::new().base_url(&url).parse(&value).map(|url| url.serialize()).ok()
url.join(&value).map(|url| url.serialize()).ok()
});
let event = ConstellationMsg::NodeStatus(status);
let ConstellationChan(ref chan) = self.constellation_chan;

View file

@ -45,4 +45,4 @@ euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
time = "0.1.12"
url = "0.5"
url = "0.5.2"

View file

@ -145,5 +145,5 @@ env_logger = "0.3"
time = "0.1.12"
bitflags = "0.3"
libc = "0.2"
url = {version = "0.5", features = ["serde_serialization", "query_encoding"]}
url = {version = "0.5.2", features = ["serde_serialization", "query_encoding"]}
euclid = {version = "0.4", features = ["plugins"]}

View file

@ -38,5 +38,5 @@ string_cache = "0.2"
euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"

View file

@ -8,7 +8,7 @@ use parser::{ParserContext, log_css_error};
use properties::longhands::font_family::parse_one_family;
use std::ascii::AsciiExt;
use string_cache::Atom;
use url::{Url, UrlParser};
use url::Url;
use util::mem::HeapSizeOf;
#[derive(Clone, Debug, HeapSizeOf, PartialEq, Eq, Deserialize, Serialize)]
@ -111,7 +111,7 @@ fn parse_one_src(context: &ParserContext, input: &mut Parser) -> Result<Source,
return Ok(Source::Local(try!(input.parse_nested_block(parse_one_non_generic_family_name))))
}
let url = try!(input.expect_url());
let url = UrlParser::new().base_url(context.base_url).parse(&url).unwrap_or_else(
let url = context.base_url.join(&url).unwrap_or_else(
|_error| url!("about:invalid"));
// Parsing optional format()

View file

@ -7,7 +7,7 @@ use cssparser::{Parser, SourcePosition};
use msg::ParseErrorReporter;
use selectors::parser::ParserContext as SelectorParserContext;
use stylesheets::Origin;
use url::{Url, UrlParser};
use url::Url;
pub struct ParserContext<'a> {
pub stylesheet_origin: Origin,
@ -33,7 +33,7 @@ impl<'a> ParserContext<'a> {
impl<'a> ParserContext<'a> {
pub fn parse_url(&self, input: &str) -> Url {
UrlParser::new().base_url(self.base_url).parse(input)
self.base_url.join(input)
.unwrap_or_else(|_| url!("about:invalid"))
}
}

View file

@ -23,5 +23,5 @@ rustc-serialize = "0.3"
selectors = "0.2"
serde = "0.6"
serde_macros = "0.6"
url = "0.5"
url = "0.5.2"

View file

@ -52,5 +52,5 @@ string_cache = "0.2"
lazy_static = "0.1"
getopts = "0.2.11"
hyper = "0.7"
url = "0.5"
url = "0.5.2"
uuid = "0.1.17"

View file

@ -31,5 +31,5 @@ log = "0.3"
hyper = "0.7"
rustc-serialize = "0.3.4"
regex = "0.1.33"
url = "0.5"
url = "0.5.2"
uuid = "0.1"

View file

@ -10,7 +10,7 @@ crate-type = ["dylib"]
[dependencies]
log = "0.3"
url = "0.5"
url = "0.5.2"
libc = "0.2"
euclid = {version = "0.4", features = ["plugins"]}
gleam = "0.2"

View file

@ -15,7 +15,7 @@ headless = ["servo-glutin/headless"]
time = "0.1.12"
bitflags = "0.3"
libc = "0.2"
url = "0.5"
url = "0.5.2"
gleam = "0.2"
euclid = {version = "0.4", features = ["plugins"]}
servo-glutin = "0.4"

View file

@ -42,7 +42,7 @@ path = "../../components/util"
[dependencies]
env_logger = "0.3"
url = "0.5"
url = "0.5.2"
time = "0.1.17"
errno = "0.1"
libc = "0.2"

View file

@ -32,6 +32,6 @@ git = "https://github.com/servo/ipc-channel"
[dependencies]
cookie = "0.2"
hyper = "0.7"
url = "0.5"
url = "0.5.2"
time = "0.1"
flate2 = "0.2.0"

View file

@ -12,4 +12,4 @@ doctest = false
path = "../../../components/plugins"
[dependencies]
url = "0.5"
url = "0.5.2"

View file

@ -25,7 +25,7 @@ path = "../../../components/util"
[dependencies]
app_units = {version = "0.1", features = ["plugins"]}
url = "0.5"
url = "0.5.2"
cssparser = "0.4"
selectors = "0.2"
string_cache = "0.2"