Skip to content

Commit

Permalink
Add comment to useless range check
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 30, 2023
1 parent 74b4039 commit 3738f71
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ fn parse_rfc3339<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a st
}

let offset = try_consume!(scan::timezone_offset(s, |s| scan::char(s, b':'), true, false, true));
if offset <= -86_400 || offset >= 86_400 {
// This range check is similar to the one in `FixedOffset::east_opt`, so it would be redundant.
// But it is possible to read the offset directly from `Parsed`. We want to only successfully
// populate `Parsed` if the input is fully valid RFC 3339.
const MAX_OFFSET: i32 = 23 * 3600 + 59 * 60;
if offset < -MAX_OFFSET || offset > MAX_OFFSET {
return Err(OUT_OF_RANGE);
}
parsed.set_offset(i64::from(offset))?;
Expand Down

0 comments on commit 3738f71

Please sign in to comment.