Skip to content

Commit

Permalink
refactor(headers): Fail to parse single value header values
Browse files Browse the repository at this point in the history
A single value header value can't be "", so `from_one_raw_str()` now
returns `None` on empty values. This makes custom checks in headers
obsolete.

BREAKING CHANGE: `from_one_raw_str()` returns `None` on empty values.
  • Loading branch information
pyfisch committed May 2, 2015
1 parent 6b59bd2 commit a6974c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/header/common/pragma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ fn test_parse_header() {
let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap();
let d = Pragma::Ext("FoObar".to_string());
assert_eq!(c, d);
let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref());
assert_eq!(e, None);
}
8 changes: 5 additions & 3 deletions src/header/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<T> {
return None;
}
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
match str::from_utf8(&raw[0][..]) {
Ok(s) => str::FromStr::from_str(s).ok(),
Err(_) => None
if let Ok(s) = str::from_utf8(&raw[0][..]) {
if s != "" {
return str::FromStr::from_str(s).ok();
}
}
None
}

/// Reads a comma-delimited raw header into a Vec.
Expand Down

0 comments on commit a6974c9

Please sign in to comment.