diff --git a/src/components/util/url.rs b/src/components/util/url.rs index 9d673bbfb57..47c4043b330 100644 --- a/src/components/util/url.rs +++ b/src/components/util/url.rs @@ -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 { +pub fn try_parse_url(str_url: &str, base_url: Option) -> Result { 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 } }; - // 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 { + // 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;