From 971bbc6945dec206c53f91476bf4d028841c7406 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 23 Jul 2023 17:37:24 +0200 Subject: [PATCH] fix a bug --- src/mime/type.rs | 27 +++++++++++++++++++++++---- src/text/whitespace.rs | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/mime/type.rs b/src/mime/type.rs index c56b96e..383e584 100644 --- a/src/mime/type.rs +++ b/src/mime/type.rs @@ -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> { - 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"[..] + ])), + } + ], + )) + ); + } } diff --git a/src/text/whitespace.rs b/src/text/whitespace.rs index 37865f5..be0747d 100644 --- a/src/text/whitespace.rs +++ b/src/text/whitespace.rs @@ -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