From 470250eb2ad535ca057d1a532ef97ed13f8a059c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 6 May 2014 10:05:47 +0530 Subject: [PATCH] Split parse_url to allow for external error handling --- src/components/util/url.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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;