mirror of
https://github.com/servo/servo.git
synced 2025-06-23 16:44:33 +01:00
Split parse_url to allow for external error handling
This commit is contained in:
parent
310d2a19bb
commit
470250eb2a
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->
|
||||
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 schm = std_url::get_scheme(str_url);
|
||||
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).ok().expect("URL parsing failed")
|
||||
std_url::from_str(str_url)
|
||||
}
|
||||
|
||||
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)]
|
||||
mod parse_url_tests {
|
||||
use super::parse_url;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue