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:
18
src/uri.rs
18
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),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user