Skip to content

Commit a6974c9

Browse files
committed
refactor(headers): Fail to parse single value header values
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.
1 parent 6b59bd2 commit a6974c9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/header/common/pragma.rs

+2
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ fn test_parse_header() {
5757
let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap();
5858
let d = Pragma::Ext("FoObar".to_string());
5959
assert_eq!(c, d);
60+
let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref());
61+
assert_eq!(e, None);
6062
}

src/header/parsing.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<T> {
99
return None;
1010
}
1111
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
12-
match str::from_utf8(&raw[0][..]) {
13-
Ok(s) => str::FromStr::from_str(s).ok(),
14-
Err(_) => None
12+
if let Ok(s) = str::from_utf8(&raw[0][..]) {
13+
if s != "" {
14+
return str::FromStr::from_str(s).ok();
15+
}
1516
}
17+
None
1618
}
1719

1820
/// Reads a comma-delimited raw header into a Vec.

0 commit comments

Comments
 (0)