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::{ use nom::{
bytes::complete::tag, bytes::complete::{is_not, tag},
combinator::map, combinator::{map, opt},
multi::many0, multi::many0,
sequence::{preceded, tuple}, sequence::{preceded, terminated, tuple},
IResult, IResult,
}; };
use crate::mime::charset::EmailCharset; use crate::mime::charset::EmailCharset;
use crate::text::misc_token::{mime_word, MIMEWord}; use crate::text::misc_token::{mime_word, MIMEWord};
use crate::text::words::mime_atom; use crate::text::words::mime_atom;
use crate::text::ascii;
// --------- NAIVE TYPE // --------- NAIVE TYPE
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -41,7 +42,7 @@ pub fn parameter(input: &[u8]) -> IResult<&[u8], Parameter> {
)(input) )(input)
} }
pub fn parameter_list(input: &[u8]) -> IResult<&[u8], Vec<Parameter>> { 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 // 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]> { pub fn obs_crlf(input: &[u8]) -> IResult<&[u8], &[u8]> {
alt((tag(ascii::CRLF), tag(&[ascii::CR]), tag(&[ascii::LF])))(input) alt((tag(ascii::CRLF), tag(&[ascii::CR]), tag(&[ascii::LF])))(input)
} }
pub fn line(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> { pub fn line(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
// is_not(CRLF) is a hack, it means "is not CR or LF" // is_not(CRLF) is a hack, it means "is not CR or LF"
// and not "is not CRLF". In other words, it continues while // and not "is not CRLF". In other words, it continues while