Skip to content

Commit

Permalink
fix(headers): Do not parse empty values in list headers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pyfisch committed Apr 28, 2015
1 parent 621ef52 commit 093a29b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/header/common/accept_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ header! {
test_accept_encoding {
// From the RFC
test_header!(test1, vec![b"compress, gzip"]);
test_header!(test2, vec![b""]);
test_header!(test2, vec![b""], Some(AcceptEncoding(vec![])));
test_header!(test3, vec![b"*"]);
// Note: Removed quality 1 from gzip
test_header!(test4, vec![b"compress;q=0.5, gzip"]);
Expand Down
5 changes: 4 additions & 1 deletion src/header/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> {
Ok(s) => {
Some(s
.split(',')
.map(|x| x.trim())
.filter_map(|x| match x.trim() {
"" => None,
y => Some(y)
})
.filter_map(|x| x.parse().ok())
.collect())
}
Expand Down

0 comments on commit 093a29b

Please sign in to comment.