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.
This commit is contained in:
Pyfisch
2015-04-28 08:57:35 +02:00
parent 621ef521f6
commit 093a29bab7
2 changed files with 5 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ header! {
test_accept_encoding { test_accept_encoding {
// From the RFC // From the RFC
test_header!(test1, vec![b"compress, gzip"]); 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"*"]); test_header!(test3, vec![b"*"]);
// Note: Removed quality 1 from gzip // Note: Removed quality 1 from gzip
test_header!(test4, vec![b"compress;q=0.5, gzip"]); test_header!(test4, vec![b"compress;q=0.5, gzip"]);

View File

@@ -31,7 +31,10 @@ pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> {
Ok(s) => { Ok(s) => {
Some(s Some(s
.split(',') .split(',')
.map(|x| x.trim()) .filter_map(|x| match x.trim() {
"" => None,
y => Some(y)
})
.filter_map(|x| x.parse().ok()) .filter_map(|x| x.parse().ok())
.collect()) .collect())
} }