mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
auto merge of #2341 : Manishearth/servo/error-parse, r=jdm
Sometimes it's useful to bubble out the error from the URL parsing so the caller can deal with the result as per its needs. [The XHR `open()`](http://xhr.spec.whatwg.org/#the-open()-method), for example, is one place where the bubbling out of an error is required. Blocks #2282
This commit is contained in:
commit
1879bf95ee
1 changed files with 8 additions and 3 deletions
|
@ -17,7 +17,7 @@ Create a URL object from a string. Does various helpful browsery things like
|
||||||
|
|
||||||
*/
|
*/
|
||||||
// TODO: about:failure->
|
// TODO: about:failure->
|
||||||
pub fn parse_url(str_url: &str, base_url: Option<std_url::Url>) -> std_url::Url {
|
pub fn try_parse_url(str_url: &str, base_url: Option<std_url::Url>) -> Result<std_url::Url, ~str> {
|
||||||
let str_url = str_url.trim_chars(& &[' ', '\t', '\n', '\r', '\x0C']).to_owned();
|
let str_url = str_url.trim_chars(& &[' ', '\t', '\n', '\r', '\x0C']).to_owned();
|
||||||
let schm = std_url::get_scheme(str_url);
|
let schm = std_url::get_scheme(str_url);
|
||||||
let str_url = match schm {
|
let str_url = match schm {
|
||||||
|
@ -83,10 +83,15 @@ pub fn parse_url(str_url: &str, base_url: Option<std_url::Url>) -> std_url::Url
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: Need to handle errors
|
std_url::from_str(str_url)
|
||||||
std_url::from_str(str_url).ok().expect("URL parsing failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_url(str_url: &str, base_url: Option<std_url::Url>) -> std_url::Url {
|
||||||
|
// FIXME: Need to handle errors
|
||||||
|
try_parse_url(str_url, base_url).ok().expect("URL parsing failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod parse_url_tests {
|
mod parse_url_tests {
|
||||||
use super::parse_url;
|
use super::parse_url;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue