Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions imap-proto/src/parser/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,9 @@ pub fn literal(input: &[u8]) -> IResult<&[u8], &[u8]> {

let (remaining, data) = take(count)(remaining)?;

if !data.iter().all(|byte| is_char8(*byte)) {
// FIXME: what ErrorKind should this have?
return Err(nom::Err::Error(nom::error::Error::new(
remaining,
nom::error::ErrorKind::Verify,
)));
}

Ok((remaining, data))
}

/// CHAR8 = %x01-ff ; any OCTET except NUL, %x00
pub fn is_char8(i: u8) -> bool {
i != 0
}

// ----- astring ----- atom (roughly) or string

// astring = 1*ASTRING-CHAR / string
Expand Down Expand Up @@ -285,6 +272,16 @@ mod tests {
}
}

#[test]
fn test_string_literal_containing_null() {
match string(b"{5}\r\nX\0Y\0Z") {
Ok((_, value)) => {
assert_eq!(value, b"X\0Y\0Z");
}
rsp => panic!("unexpected response {rsp:?}"),
}
}

#[test]
fn test_astring() {
match astring(b"text ") {
Expand Down