From 4dab4a70fe82ac714ee7289b31e8da0585430509 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 16 Dec 2024 02:53:32 -0500 Subject: [PATCH] Remove unnecessary check --- tests/parsing.rs | 1 + time/src/parsing/combinator/rfc/rfc2822.rs | 21 +++++++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/parsing.rs b/tests/parsing.rs index 25f69f6969..c73f243de8 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -148,6 +148,7 @@ fn rfc_2822() -> time::Result<()> { " \t Sat,\r\n \ (\tfoo012FOO!)\ (\u{1}\u{b}\u{e}\u{7f})\ + (\\\u{0})\ (\\\u{1}\\\u{9}\\\u{28}\\\u{29}\\\\u{5c}\\\u{7f})\ (\\\n\\\u{b})\ 02 \r\n \r\n Jan 2021 03:04:05 GMT", diff --git a/time/src/parsing/combinator/rfc/rfc2822.rs b/time/src/parsing/combinator/rfc/rfc2822.rs index 8410de06e3..0e886ee4fd 100644 --- a/time/src/parsing/combinator/rfc/rfc2822.rs +++ b/time/src/parsing/combinator/rfc/rfc2822.rs @@ -58,22 +58,15 @@ fn ctext(input: &[u8]) -> Option> { /// Consume the `quoted_pair` rule. fn quoted_pair(mut input: &[u8]) -> Option> { input = ascii_char::(input)?.into_inner(); - - let old_input_len = input.len(); - input = text(input).into_inner(); - // If nothing is parsed, this means we hit the `obs-text` rule and nothing matched. This is - // technically a success, but we should still check the `obs-qp` rule to ensure we consume - // everything possible. - if input.len() == old_input_len { - match input { - [0..=127, rest @ ..] => Some(ParsedItem(rest, ())), - _ => Some(ParsedItem(input, ())), - } - } else { - Some(ParsedItem(input, ())) - } + // If nothing is parsed by `text`, this means by hit the `obs-text` rule and nothing matched. + // This is technically a success, and we used to check the `obs-qp` rule to ensure everything + // possible was consumed. After further analysis, it was determined that this check was + // unnecessary due to `obs-text` wholly subsuming `obs-qp` in this context. For this reason, if + // `text` fails to parse anything, we consider it a success without further consideration. + + Some(ParsedItem(input, ())) } /// Consume the `no_ws_ctl` rule.