Skip to content

Commit 093a29b

Browse files
committed
fix(headers): Do not parse empty values in list headers.
In empty list header values ``, or list header values with empty items `foo, , bar`, the empty value is parsed, if the parser does not reject empty values an item is added to the resulting header. There can't be empty values. Added a test for it in AcceptEncoding.
1 parent 621ef52 commit 093a29b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/header/common/accept_encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ header! {
2020
test_accept_encoding {
2121
// From the RFC
2222
test_header!(test1, vec![b"compress, gzip"]);
23-
test_header!(test2, vec![b""]);
23+
test_header!(test2, vec![b""], Some(AcceptEncoding(vec![])));
2424
test_header!(test3, vec![b"*"]);
2525
// Note: Removed quality 1 from gzip
2626
test_header!(test4, vec![b"compress;q=0.5, gzip"]);

src/header/parsing.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> {
3131
Ok(s) => {
3232
Some(s
3333
.split(',')
34-
.map(|x| x.trim())
34+
.filter_map(|x| match x.trim() {
35+
"" => None,
36+
y => Some(y)
37+
})
3538
.filter_map(|x| x.parse().ok())
3639
.collect())
3740
}

0 commit comments

Comments
 (0)