Skip to content

Commit

Permalink
Split parse_url to allow for external error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 6, 2014
1 parent 310d2a1 commit 470250e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/util/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -83,10 +83,15 @@ pub fn parse_url(str_url: &str, base_url: Option<std_url::Url>) -> std_url::Url
}
};

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
std_url::from_str(str_url).ok().expect("URL parsing failed")
try_parse_url(str_url, base_url).ok().expect("URL parsing failed")
}


#[cfg(test)]
mod parse_url_tests {
use super::parse_url;
Expand Down

5 comments on commit 470250e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at Manishearth@470250e

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Manishearth/servo/error-parse = 470250e into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manishearth/servo/error-parse = 470250e merged ok, testing candidate = 1879bf9

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1879bf9

Please sign in to comment.