From 8faf5b8bb1bea34217480039109fb68d2172fa9d Mon Sep 17 00:00:00 2001 From: M3rs Date: Sun, 22 Jan 2017 11:38:45 -0600 Subject: [PATCH] refactor(uri): Add errors to scheme uri Add errors to scheme uri (contains "://"). Check for: - Valid schemes (ftp, gopher, http, https, ws, wss) - Invalid schemes (blob, file), or anything else -> Err(Error::Method) - Authority is not empty (i.e. "http://") https://github.com/hyperium/hyper/issues/1022 --- src/uri.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/uri.rs b/src/uri.rs index 22c767f7..8d017aac 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -62,10 +62,24 @@ impl Uri { fragment: parse_fragment(s), }) } else if s.contains("://") { + let scheme = parse_scheme(s); + let auth = parse_authority(s); + if let Some(end) = scheme { + match &s[..end] { + "ftp" | "gopher" | "http" | "https" | "ws" | "wss" => {}, + "blob" | "file" => return Err(Error::Method), + _ => return Err(Error::Method), + } + if let Some(a) = auth { + if (end + 3) == a { + return Err(Error::Method); + } + } + } Ok(Uri { source: s.to_owned().into(), - scheme_end: parse_scheme(s), - authority_end: parse_authority(s), + scheme_end: scheme, + authority_end: auth, query: parse_query(s), fragment: parse_fragment(s), })