Don't crash when parsing empty result

Partial fix for #81.
This commit is contained in:
Jon Gjengset 2018-07-18 16:14:28 -04:00
parent c095ee2aa0
commit dea9398e08
No known key found for this signature in database
GPG key ID: D64AC9D67176DC71

View file

@ -25,9 +25,13 @@ unsafe fn parse_many<T, F>(lines: Vec<u8>, mut map: F) -> ZeroCopyResult<Vec<T>>
where
F: FnMut(Response<'static>) -> MapOrNot<T>,
{
let f = |mut lines| {
let f = |mut lines: &'static [u8]| {
let mut things = Vec::new();
loop {
if lines.is_empty() {
break Ok(things);
}
match imap_proto::parse_response(lines) {
IResult::Done(rest, resp) => {
lines = rest;
@ -36,10 +40,6 @@ where
MapOrNot::Map(t) => things.push(t),
MapOrNot::Not(resp) => break Err(resp.into()),
}
if lines.is_empty() {
break Ok(things);
}
}
_ => {
break Err(Error::Parse(ParseError::Invalid(lines.to_vec())));
@ -237,6 +237,13 @@ mod tests {
assert_eq!(names[0].name(), "INBOX");
}
#[test]
fn parse_fetches_empty() {
let lines = b"";
let fetches = parse_fetches(lines.to_vec()).unwrap();
assert!(fetches.is_empty());
}
#[test]
fn parse_fetches_test() {
let lines = b"\