Skip to content

Commit

Permalink
Fix empty Method considered as valid (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
theredfish authored and seanmonstar committed Oct 18, 2018
1 parent f8b3693 commit 4a71708
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/method.rs
Expand Up @@ -143,6 +143,9 @@ impl Method {
/// Converts a slice of bytes to an HTTP method.
pub fn from_bytes(src: &[u8]) -> Result<Method, InvalidMethod> {
match src.len() {
0 => {
Err(InvalidMethod::new())
}
3 => {
match src {
b"GET" => Ok(Method(Get)),
Expand Down Expand Up @@ -411,3 +414,9 @@ fn test_method_eq() {
assert_eq!(&Method::GET, Method::GET);
assert_eq!(Method::GET, &Method::GET);
}

#[test]
fn test_invalid_method() {
assert!(Method::from_str("").is_err());
assert!(Method::from_bytes(b"").is_err());
}

0 comments on commit 4a71708

Please sign in to comment.