mirror of
https://github.com/bspeice/dtparse
synced 2025-07-05 15:54:55 -04:00
Add fuzzing, find and fix a parser bug.
This commit is contained in:
@ -952,7 +952,11 @@ impl Parser {
|
||||
if let Some(value) = info.get_month(&tokens[idx + 4]) {
|
||||
ymd.append(value as i32, &tokens[idx + 4], Some(YMDLabel::Month))?;
|
||||
} else {
|
||||
ymd.append(tokens[idx + 4].parse::<i32>().unwrap(), &tokens[idx + 4], None)?;
|
||||
if let Ok(val) = tokens[idx + 4].parse::<i32>() {
|
||||
ymd.append(val, &tokens[idx + 4], None)?;
|
||||
} else {
|
||||
return Err(ParseInternalError::ValueError("".to_owned()));
|
||||
}
|
||||
}
|
||||
|
||||
idx += 2;
|
||||
|
@ -3,13 +3,16 @@ use std::collections::HashMap;
|
||||
|
||||
use parse;
|
||||
use ParseError;
|
||||
use ParseInternalError;
|
||||
use Parser;
|
||||
|
||||
#[test]
|
||||
fn test_fuzz() {
|
||||
|
||||
assert_eq!(parse("\x2D\x38\x31\x39\x34\x38\x34"), Err(ParseError::InvalidMonth));
|
||||
|
||||
// Garbage in the third delimited field
|
||||
assert_eq!(parse("2..\x00\x000d\x00+\x010d\x01\x00\x00\x00+"),
|
||||
Err(ParseError::InternalError(ParseInternalError::ValueError("".to_owned()))));
|
||||
let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0);
|
||||
let mut p = Parser::default();
|
||||
let res = p.parse("\x0D\x31", None, None, false, false, Some(&default), false, HashMap::new()).unwrap();
|
||||
|
Reference in New Issue
Block a user