From 4ff4c57e2cdd4a00728eda1ee227e4a3a2734816 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Mon, 8 Jan 2024 19:31:34 +0100 Subject: [PATCH] Clippy fixes --- resources/date.json | 2 +- src/decoders/base64.rs | 180 +++++++++++++++---------------- src/decoders/charsets/map.rs | 54 +++++----- src/decoders/html.rs | 172 ++++++++++++++--------------- src/decoders/quoted_printable.rs | 41 +++---- src/parsers/fields/date.rs | 2 +- src/parsers/header.rs | 107 ++++++------------ src/parsers/mime.rs | 6 +- 8 files changed, 260 insertions(+), 304 deletions(-) diff --git a/resources/date.json b/resources/date.json index b492c3d..ddc5eee 100644 --- a/resources/date.json +++ b/resources/date.json @@ -170,7 +170,7 @@ { "header": " 4 8 15 16 23 42, 4 8 15 16 23 42, 4 8 15 16 23 42, ", "expected": { - "year": 1915, + "year": 2015, "month": 8, "day": 4, "hour": 16, diff --git a/src/decoders/base64.rs b/src/decoders/base64.rs index 2583bf3..7afffd7 100644 --- a/src/decoders/base64.rs +++ b/src/decoders/base64.rs @@ -290,96 +290,6 @@ impl<'x> MessageStream<'x> { } } -#[cfg(test)] -mod tests { - use crate::parsers::MessageStream; - - #[test] - fn decode_base64() { - for (encoded_str, expected_result) in [ - ("VGVzdA==", "Test"), - ("WWU=", "Ye"), - ("QQ==", "A"), - ("cm8=", "ro"), - ( - "QXJlIHlvdSBhIFNoaW1hbm8gb3IgQ2FtcGFnbm9sbyBwZXJzb24/", - "Are you a Shimano or Campagnolo person?", - ), - ( - "PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keT4KPC9ib2R5Pgo8L2h0bWw+Cg==", - "\n\n\n\n\n", - ), - ( - "PCFET0NUWVBFIGh0bWw+CjxodG1sPg\no8Ym9ke\nT4KPC 9ib2R5Pg\n o8L2h0bWw+Cg==", - "\n\n\n\n\n", - ), - ("w6HDqcOtw7PDug==", "áéíóú"), - ("====", ""), - ("w6HDq!cOtw7PDug=", ""), - ("w6 HD qcOt", "áéí"), - ("cmáé", ""), - ("áé", ""), - ("w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==", "áéíóú"), - ("w6HDqcOtw7PDug==", "áéíóú"), - ] { - assert_eq!( - super::base64_decode(encoded_str.as_bytes()).unwrap_or_default(), - expected_result.as_bytes(), - "Failed for {encoded_str:?}", - ); - } - } - - #[test] - fn decode_base64_mime() { - for (encoded_str, expected_result) in [ - ("VGVzdA==\r\n--boundary\n", "Test"), - ( - "PCFET0NUWVBFIGh0bWw+CjxodG1sPg\no8Ym9ke\nT4KPC 9ib2R5Pg\n o8L2h0bWw+Cg==\r\n--boundary--\r\n", - "\n\n\n\n\n", - ), - ("w6HDqcOtw7PDug==\r\n--boundary \n", "áéíóú"), - ("w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==\r\n--boundary\n", "áéíóú"), - ("w6HDqcOtw7PDug==--boundary", "áéíóú"), - ( - "w6HDqcOtw7PDug==\n--boundary--", - "áéíóú", - ), - ( - "w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==\n--boundary", - "áéíóú", - ), - ] { - let mut s = MessageStream::new(encoded_str.as_bytes()); - let (_, result) = s.decode_base64_mime(b"boundary"); - - assert_eq!( - result, - expected_result.as_bytes(), - "Failed for {encoded_str:?}", - ); - } - } - - #[test] - fn decode_base64_word() { - for (encoded_str, expected_result) in [ - ("w 6 H D q c O t w 7 P D u g== ?=", "áéíóú"), - ("w6HDqcOtw7PDug==?=", "áéíóú"), - ("w6HDqc\n Otw7PDug==?=", "áéíóú"), - ("w6HDqcOtw7PDug================?=", "áéíóú"), - ("?=", ""), - ] { - let mut s = MessageStream::new(encoded_str.as_bytes()); - assert_eq!( - s.decode_base64_word().unwrap(), - expected_result.as_bytes(), - "Failed for {encoded_str:?}", - ); - } - } -} - /* * Table adapted from Nick Galbreath's "High performance base64 encoder / decoder" * @@ -550,3 +460,93 @@ pub static BASE64_MAP: &[&[u32]] = &[ 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, ], ]; + +#[cfg(test)] +mod tests { + use crate::parsers::MessageStream; + + #[test] + fn decode_base64() { + for (encoded_str, expected_result) in [ + ("VGVzdA==", "Test"), + ("WWU=", "Ye"), + ("QQ==", "A"), + ("cm8=", "ro"), + ( + "QXJlIHlvdSBhIFNoaW1hbm8gb3IgQ2FtcGFnbm9sbyBwZXJzb24/", + "Are you a Shimano or Campagnolo person?", + ), + ( + "PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keT4KPC9ib2R5Pgo8L2h0bWw+Cg==", + "\n\n\n\n\n", + ), + ( + "PCFET0NUWVBFIGh0bWw+CjxodG1sPg\no8Ym9ke\nT4KPC 9ib2R5Pg\n o8L2h0bWw+Cg==", + "\n\n\n\n\n", + ), + ("w6HDqcOtw7PDug==", "áéíóú"), + ("====", ""), + ("w6HDq!cOtw7PDug=", ""), + ("w6 HD qcOt", "áéí"), + ("cmáé", ""), + ("áé", ""), + ("w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==", "áéíóú"), + ("w6HDqcOtw7PDug==", "áéíóú"), + ] { + assert_eq!( + super::base64_decode(encoded_str.as_bytes()).unwrap_or_default(), + expected_result.as_bytes(), + "Failed for {encoded_str:?}", + ); + } + } + + #[test] + fn decode_base64_mime() { + for (encoded_str, expected_result) in [ + ("VGVzdA==\r\n--boundary\n", "Test"), + ( + "PCFET0NUWVBFIGh0bWw+CjxodG1sPg\no8Ym9ke\nT4KPC 9ib2R5Pg\n o8L2h0bWw+Cg==\r\n--boundary--\r\n", + "\n\n\n\n\n", + ), + ("w6HDqcOtw7PDug==\r\n--boundary \n", "áéíóú"), + ("w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==\r\n--boundary\n", "áéíóú"), + ("w6HDqcOtw7PDug==--boundary", "áéíóú"), + ( + "w6HDqcOtw7PDug==\n--boundary--", + "áéíóú", + ), + ( + "w\n6\nH\nD\nq\nc\nO\nt\nw\n7\n P\tD u g\n==\n--boundary", + "áéíóú", + ), + ] { + let mut s = MessageStream::new(encoded_str.as_bytes()); + let (_, result) = s.decode_base64_mime(b"boundary"); + + assert_eq!( + result, + expected_result.as_bytes(), + "Failed for {encoded_str:?}", + ); + } + } + + #[test] + fn decode_base64_word() { + for (encoded_str, expected_result) in [ + ("w 6 H D q c O t w 7 P D u g== ?=", "áéíóú"), + ("w6HDqcOtw7PDug==?=", "áéíóú"), + ("w6HDqc\n Otw7PDug==?=", "áéíóú"), + ("w6HDqcOtw7PDug================?=", "áéíóú"), + ("?=", ""), + ] { + let mut s = MessageStream::new(encoded_str.as_bytes()); + assert_eq!( + s.decode_base64_word().unwrap(), + expected_result.as_bytes(), + "Failed for {encoded_str:?}", + ); + } + } +} diff --git a/src/decoders/charsets/map.rs b/src/decoders/charsets/map.rs index 3d8c133..9b8e274 100644 --- a/src/decoders/charsets/map.rs +++ b/src/decoders/charsets/map.rs @@ -81,33 +81,6 @@ pub fn no_op(_bytes: &[u8]) -> String { "".to_string() } -#[cfg(test)] -mod tests { - use super::charset_decoder; - - #[test] - #[allow(clippy::uninlined_format_args)] - fn decoder_charset() { - let inputs = [ - "l8", - //"utf-8", - "utf-7", - //"US-Ascii", - "csgb18030", - "iso-8859-1", - "extended_unix_code_packed_format_for_japanese", - ]; - - for input in inputs { - assert!( - charset_decoder(input.as_bytes()).is_some(), - "Failed for {}", - input - ); - } - } -} - // Perfect hashing table for charset names static CH_HASH: &[u32] = &[ 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, @@ -1648,3 +1621,30 @@ static FNC_MAP: &[for<'x> fn(&'x [u8]) -> String; 758] = &[ no_op, decoder_gb18030, ]; + +#[cfg(test)] +mod tests { + use super::charset_decoder; + + #[test] + #[allow(clippy::uninlined_format_args)] + fn decoder_charset() { + let inputs = [ + "l8", + //"utf-8", + "utf-7", + //"US-Ascii", + "csgb18030", + "iso-8859-1", + "extended_unix_code_packed_format_for_japanese", + ]; + + for input in inputs { + assert!( + charset_decoder(input.as_bytes()).is_some(), + "Failed for {}", + input + ); + } + } +} diff --git a/src/decoders/html.rs b/src/decoders/html.rs index 64661c0..be1c21d 100644 --- a/src/decoders/html.rs +++ b/src/decoders/html.rs @@ -276,92 +276,6 @@ pub fn text_to_html(input: &str) -> String { String::from_utf8(result).unwrap() } -#[cfg(test)] -mod tests { - - use crate::decoders::html::{add_html_token, html_to_text, text_to_html}; - - #[test] - fn convert_text_to_html() { - let inputs = [ - ( - "hello\nworld\n", - "hello
world
", - ), - ("using <>\n", "using <>
"), - ]; - - for input in inputs { - assert_eq!(text_to_html(input.0), input.1); - } - } - - #[test] - fn convert_html_to_text() { - let inputs = [ - ("hello
world
", "hello\nworld\n"), - ("using <>
", "using <>\n"), - ("test tag
", "test tag\n"), - ("<>< >>hello world< br \n />", ">hello world\n"), - ( - concat!( - "ignore headxyz", - "

<body>

" - ), - "", - ), - ( - concat!( - "

what is ♥?

ßĂΒγ ", - "don't hurt me.

" - ), - "what is ♥?\nßĂΒγ don't hurt me.\n", - ), - ( - concat!( - "", - "this is the actual text" - ), - "this is the actual text", - ), - ( - " < p > hello < / p > < p > world < / p > !!! < br > ", - "hello\nworld\n!!!\n", - ), - ( - "

please unsubscribe here.

", - "please unsubscribe here.\n", - ), - ]; - - for input in inputs { - assert_eq!(html_to_text(input.0), input.1, "Failed for '{:?}'", input.0); - } - } - - #[test] - fn convert_html_entity() { - let inputs = [ - ("<", "<"), - (" ", " "), - (" ", " "), - (" ", "\u{a0}"), - ("∳", "∳"), - ("↷", "↷"), - ("→", "→"), - ("�", "�"), - ("&hmmm", "&hmmm"), - ]; - - for input in inputs { - let mut result = String::with_capacity(input.0.len()); - add_html_token(&mut result, input.0.as_bytes(), false); - assert_eq!(result, input.1, "Failed for '{:?}", input.0); - } - } -} - static ENTITY_HASH: &[u32; 260] = &[ 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, 18080, @@ -1082,3 +996,89 @@ static ENTITY_MAP: &[u32; 18016] = &[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x021B7, ]; + +#[cfg(test)] +mod tests { + + use crate::decoders::html::{add_html_token, html_to_text, text_to_html}; + + #[test] + fn convert_text_to_html() { + let inputs = [ + ( + "hello\nworld\n", + "hello
world
", + ), + ("using <>\n", "using <>
"), + ]; + + for input in inputs { + assert_eq!(text_to_html(input.0), input.1); + } + } + + #[test] + fn convert_html_to_text() { + let inputs = [ + ("hello
world
", "hello\nworld\n"), + ("using <>
", "using <>\n"), + ("test tag
", "test tag\n"), + ("<>< >>hello world< br \n />", ">hello world\n"), + ( + concat!( + "ignore headxyz", + "

<body>

" + ), + "", + ), + ( + concat!( + "

what is ♥?

ßĂΒγ ", + "don't hurt me.

" + ), + "what is ♥?\nßĂΒγ don't hurt me.\n", + ), + ( + concat!( + "", + "this is the actual text" + ), + "this is the actual text", + ), + ( + " < p > hello < / p > < p > world < / p > !!! < br > ", + "hello\nworld\n!!!\n", + ), + ( + "

please unsubscribe here.

", + "please unsubscribe here.\n", + ), + ]; + + for input in inputs { + assert_eq!(html_to_text(input.0), input.1, "Failed for '{:?}'", input.0); + } + } + + #[test] + fn convert_html_entity() { + let inputs = [ + ("<", "<"), + (" ", " "), + (" ", " "), + (" ", "\u{a0}"), + ("∳", "∳"), + ("↷", "↷"), + ("→", "→"), + ("�", "�"), + ("&hmmm", "&hmmm"), + ]; + + for input in inputs { + let mut result = String::with_capacity(input.0.len()); + add_html_token(&mut result, input.0.as_bytes(), false); + assert_eq!(result, input.1, "Failed for '{:?}", input.0); + } + } +} diff --git a/src/decoders/quoted_printable.rs b/src/decoders/quoted_printable.rs index 4493d9a..0081b78 100644 --- a/src/decoders/quoted_printable.rs +++ b/src/decoders/quoted_printable.rs @@ -312,6 +312,27 @@ impl<'x> MessageStream<'x> { None } } + +/* + * Adapted from Daniel Lemire's source: + * https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp + * + */ + +pub static HEX_MAP: &[i8] = &[ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, + 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +]; + #[cfg(test)] mod tests { use crate::parsers::MessageStream; @@ -468,23 +489,3 @@ mod tests { } } } - -/* - * Adapted from Daniel Lemire's source: - * https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp - * - */ - -pub static HEX_MAP: &[i8] = &[ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, - 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -]; diff --git a/src/parsers/fields/date.rs b/src/parsers/fields/date.rs index 9eaa12e..b174dfc 100644 --- a/src/parsers/fields/date.rs +++ b/src/parsers/fields/date.rs @@ -267,7 +267,7 @@ impl DateTime { impl PartialOrd for DateTime { fn partial_cmp(&self, other: &Self) -> Option { - self.cmp(other).into() + Some(self.cmp(other)) } } diff --git a/src/parsers/header.rs b/src/parsers/header.rs index 9c76e21..e0e1b57 100644 --- a/src/parsers/header.rs +++ b/src/parsers/header.rs @@ -228,82 +228,6 @@ impl<'x> HeaderName<'x> { } } -#[cfg(test)] -mod tests { - use crate::{parsers::MessageStream, HeaderName}; - - #[test] - fn header_name_parse() { - let inputs = [ - ("From: ", HeaderName::From), - ("receiVED: ", HeaderName::Received), - (" subject : ", HeaderName::Subject), - ( - "X-Custom-Field : ", - HeaderName::Other("X-Custom-Field".into()), - ), - (" T : ", HeaderName::Other("T".into())), - ("mal formed: ", HeaderName::Other("mal formed".into())), - ("MIME-version : ", HeaderName::MimeVersion), - ]; - - for (input, expected_result) in inputs { - assert_eq!( - expected_result, - MessageStream::new(input.as_bytes()) - .parse_header_name() - .unwrap(), - "Failed to parse '{input:?}'", - ); - } - } -} - -/* -type ParserFnc<'x> = fn(&mut MessageStream<'x>) -> crate::HeaderValue<'x>; - -static HDR_PARSER: &[(bool, ParserFnc)] = &[ - (false, MessageStream::parse_unstructured), // Subject = 0, - (false, MessageStream::parse_address), // From = 1, - (false, MessageStream::parse_address), // To = 2, - (false, MessageStream::parse_address), // Cc = 3, - (false, MessageStream::parse_date), // Date = 4, - (false, MessageStream::parse_address), // Bcc = 5, - (false, MessageStream::parse_address), // ReplyTo = 6, - (false, MessageStream::parse_address), // Sender = 7, - (true, MessageStream::parse_unstructured), // Comments = 8, - (false, MessageStream::parse_id), // InReplyTo = 9, - (true, MessageStream::parse_comma_separared), // Keywords = 10, - (true, MessageStream::parse_raw), // Received = 11, - (false, MessageStream::parse_id), // MessageId = 12, - (true, MessageStream::parse_id), // References = 13, (RFC 5322 recommends One) - (false, MessageStream::parse_id), // ReturnPath = 14, - (false, MessageStream::parse_raw), // MimeVersion = 15, - (false, MessageStream::parse_unstructured), // ContentDescription = 16, - (false, MessageStream::parse_id), // ContentId = 17, - (false, MessageStream::parse_comma_separared), // ContentLanguage = 18 - (false, MessageStream::parse_unstructured), // ContentLocation = 19 - (false, MessageStream::parse_unstructured), // ContentTransferEncoding = 20, - (false, MessageStream::parse_content_type), // ContentType = 21, - (false, MessageStream::parse_content_type), // ContentDisposition = 22, - (true, MessageStream::parse_address), // ResentTo = 23, - (true, MessageStream::parse_address), // ResentFrom = 24, - (true, MessageStream::parse_address), // ResentBcc = 25, - (true, MessageStream::parse_address), // ResentCc = 26, - (true, MessageStream::parse_address), // ResentSender = 27, - (true, MessageStream::parse_date), // ResentDate = 28, - (true, MessageStream::parse_id), // ResentMessageId = 29, - (false, MessageStream::parse_address), // ListArchive = 30, - (false, MessageStream::parse_address), // ListHelp = 31, - (false, MessageStream::parse_address), // ListId = 32, - (false, MessageStream::parse_address), // ListOwner = 33, - (false, MessageStream::parse_address), // ListPost = 34, - (false, MessageStream::parse_address), // ListSubscribe = 35, - (false, MessageStream::parse_address), // ListUnsubscribe = 36, - (true, MessageStream::parse_raw), // Other = 37, -]; -*/ - static HDR_HASH: &[u8] = &[ 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, @@ -461,3 +385,34 @@ static HDR_NAMES: &[&[u8]] = &[ b"", b"mime-version", ]; + +#[cfg(test)] +mod tests { + use crate::{parsers::MessageStream, HeaderName}; + + #[test] + fn header_name_parse() { + let inputs = [ + ("From: ", HeaderName::From), + ("receiVED: ", HeaderName::Received), + (" subject : ", HeaderName::Subject), + ( + "X-Custom-Field : ", + HeaderName::Other("X-Custom-Field".into()), + ), + (" T : ", HeaderName::Other("T".into())), + ("mal formed: ", HeaderName::Other("mal formed".into())), + ("MIME-version : ", HeaderName::MimeVersion), + ]; + + for (input, expected_result) in inputs { + assert_eq!( + expected_result, + MessageStream::new(input.as_bytes()) + .parse_header_name() + .unwrap(), + "Failed to parse '{input:?}'", + ); + } + } +} diff --git a/src/parsers/mime.rs b/src/parsers/mime.rs index 39bb1ef..7c5dfe2 100644 --- a/src/parsers/mime.rs +++ b/src/parsers/mime.rs @@ -134,15 +134,15 @@ impl<'x> MessageStream<'x> { self.checkpoint(); match (self.next(), self.peek()) { - (Some(&a), Some(&&b)) if a == b'\r' && b == b'\n' => { + (Some(b'\r'), Some(b'\n')) => { self.next(); false } - (Some(&a), Some(&&b)) if a == b'-' && b == b'-' => { + (Some(b'-'), Some(b'-')) => { self.next(); true } - (Some(&a), _) if a == b'\n' => false, + (Some(b'\n'), _) => false, (Some(&a), _) if a.is_ascii_whitespace() => { self.skip_crlf(); false