Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty Method considered as valid #262

Merged
merged 1 commit into from Oct 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
}