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:
		| @@ -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"]); | ||||||
|   | |||||||
| @@ -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()) | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user