1
0
mirror of https://github.com/bspeice/dtparse synced 2024-09-19 16:31:32 -04:00

#45: Fix index issue

This commit is contained in:
Bradlee Speice 2024-08-18 20:42:20 +00:00
parent 61d2aa60c6
commit c3d6730e9c
2 changed files with 10 additions and 1 deletions

View File

@ -1132,7 +1132,9 @@ impl Parser {
}
if idx + 3 < len_l && &tokens[idx + 3] == sep {
if let Some(value) = info.month_index(&tokens[idx + 4]) {
if tokens.len() <= idx + 4 {
return Err(ParseError::UnrecognizedFormat);
} else if let Some(value) = info.month_index(&tokens[idx + 4]) {
ymd.append(value as i32, &tokens[idx + 4], Some(YMDLabel::Month))?;
} else if let Ok(val) = tokens[idx + 4].parse::<i32>() {
ymd.append(val, &tokens[idx + 4], None)?;

View File

@ -97,3 +97,10 @@ fn github_36() {
let parse_result = parse(parse_str);
assert!(parse_result.is_err());
}
#[test]
fn github_45() {
assert!(parse("/2018-fifa-").is_err());
assert!(parse("/2009/07/").is_err());
assert!(parse("2021-09-").is_err());
}