refactor(uri): Improve parse_authority safety
Improve parse_authority safety with match, replace unwrap.
Also, refactor code in contains("://") block using result from the
parse_authority to also use match.
https://github.com/hyperium/hyper/issues/1022
This commit is contained in:
25
src/uri.rs
25
src/uri.rs
@@ -70,10 +70,13 @@ impl Uri {
|
|||||||
"blob" | "file" => return Err(Error::Method),
|
"blob" | "file" => return Err(Error::Method),
|
||||||
_ => return Err(Error::Method),
|
_ => return Err(Error::Method),
|
||||||
}
|
}
|
||||||
if let Some(a) = auth {
|
match auth {
|
||||||
if (end + 3) == a {
|
Some(a) => {
|
||||||
return Err(Error::Method);
|
if (end + 3) == a {
|
||||||
}
|
return Err(Error::Method);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => return Err(Error::Method),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Uri {
|
Ok(Uri {
|
||||||
@@ -181,13 +184,13 @@ fn parse_scheme(s: &str) -> Option<usize> {
|
|||||||
|
|
||||||
fn parse_authority(s: &str) -> Option<usize> {
|
fn parse_authority(s: &str) -> Option<usize> {
|
||||||
let v: Vec<&str> = s.split("://").collect();
|
let v: Vec<&str> = s.split("://").collect();
|
||||||
let auth = v.last().unwrap()
|
match v.last() {
|
||||||
.split("/")
|
Some(auth) => Some(auth.split("/")
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or(s)
|
.unwrap_or(s)
|
||||||
.len() + if v.len() == 2 { v[0].len() + 3 } else { 0 };
|
.len() + if v.len() == 2 { v[0].len() + 3 } else { 0 }),
|
||||||
|
None => None,
|
||||||
return Some(auth);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_query(s: &str) -> Option<usize> {
|
fn parse_query(s: &str) -> Option<usize> {
|
||||||
|
|||||||
Reference in New Issue
Block a user