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
This commit is contained in:
M3rs
2017-01-22 11:38:45 -06:00
parent 37b26e21e8
commit 8faf5b8bb1

View File

@@ -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),
})