fix a bug

This commit is contained in:
Quentin 2023-07-23 17:37:24 +02:00
parent 56fea0d869
commit 971bbc6945
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 24 additions and 4 deletions

View file

@ -1,14 +1,15 @@
use nom::{
bytes::complete::tag,
combinator::map,
bytes::complete::{is_not, tag},
combinator::{map, opt},
multi::many0,
sequence::{preceded, tuple},
sequence::{preceded, terminated, tuple},
IResult,
};
use crate::mime::charset::EmailCharset;
use crate::text::misc_token::{mime_word, MIMEWord};
use crate::text::words::mime_atom;
use crate::text::ascii;
// --------- NAIVE TYPE
#[derive(Debug, PartialEq)]
@ -41,7 +42,7 @@ pub fn parameter(input: &[u8]) -> IResult<&[u8], Parameter> {
)(input)
}
pub fn parameter_list(input: &[u8]) -> IResult<&[u8], Vec<Parameter>> {
many0(preceded(tag(";"), parameter))(input)
terminated(many0(preceded(tag(";"), parameter)), opt(tag(";")))(input)
}
// MIME TYPES TRANSLATED TO RUST TYPING SYSTEM
@ -253,4 +254,22 @@ mod tests {
))
);
}
#[test]
fn test_parameter_terminated_with_semi_colon() {
assert_eq!(
parameter_list(b";boundary=\"festivus\";"),
Ok((
&b""[..],
vec![
Parameter {
name: &b"boundary"[..],
value: MIMEWord::Quoted(QuotedString(vec![
&b"festivus"[..]
])),
}
],
))
);
}
}

View file

@ -24,6 +24,7 @@ use nom::{
pub fn obs_crlf(input: &[u8]) -> IResult<&[u8], &[u8]> {
alt((tag(ascii::CRLF), tag(&[ascii::CR]), tag(&[ascii::LF])))(input)
}
pub fn line(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
// is_not(CRLF) is a hack, it means "is not CR or LF"
// and not "is not CRLF". In other words, it continues while