Skip to content

Commit

Permalink
Remove unnecessary check
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Dec 16, 2024
1 parent dad76cb commit 4dab4a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions tests/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 7 additions & 14 deletions time/src/parsing/combinator/rfc/rfc2822.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,15 @@ fn ctext(input: &[u8]) -> Option<ParsedItem<'_, ()>> {
/// Consume the `quoted_pair` rule.
fn quoted_pair(mut input: &[u8]) -> Option<ParsedItem<'_, ()>> {
input = ascii_char::<b'\\'>(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.
Expand Down

0 comments on commit 4dab4a7

Please sign in to comment.