Skip to content

Commit

Permalink
[8570]fix: raise exception for years less than 1600
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawHatDrag0n committed Jan 27, 2024
1 parent ef53708 commit 025d840
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ impl Date {
let y4 = get_digit_unchecked!(bytes, 3, InvalidCharYear) as u16;
year = y1 * 1000 + y2 * 100 + y3 * 10 + y4;

if year < 1600 {
return Err(ParseError::YearTooSmall);
}

match bytes.get_unchecked(4) {
b'-' => (),
_ => return Err(ParseError::InvalidCharDateSep),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ pub enum ParseError {
DateTooLarge,
/// numeric times may not exceed 86,399 seconds
TimeTooLarge,
/// years before 1600 are not supported
YearTooSmall,
}

#[derive(Debug, Display, EnumMessage, PartialEq, Eq, Clone)]
Expand Down
1 change: 1 addition & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ param_tests! {
date_unix_before_watershed: ok => "19999872000", "2603-10-10";
date_unix_after_watershed: ok => "20044800000", "1970-08-21";
date_unix_too_low: err => "-20000000000", DateTooSmall;
date_year_too_low: err => "1500-01-01T00:00:00+00:00", YearTooSmall;
}

#[test]
Expand Down

0 comments on commit 025d840

Please sign in to comment.