diff --git a/src/lib.rs b/src/lib.rs index 0404f5d..e85a684 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -838,13 +838,14 @@ impl Parser { } } else if res.hour.is_some() && (l[i] == "+" || l[i] == "-") { let signal = if l[i] == "+" { 1 } else { -1 }; - let len_li = l[i].len(); + // check next index's length + let timezone_len = l[i + 1].len(); let mut hour_offset: Option = None; let mut min_offset: Option = None; // TODO: check that l[i + 1] is integer? - if len_li == 4 { + if timezone_len == 4 { // -0300 hour_offset = Some(l[i + 1][..2].parse::()?); min_offset = Some(l[i + 1][2..4].parse::()?); @@ -858,7 +859,7 @@ impl Parser { Some(l[i + 3].parse::()?) }; i += 2; - } else if len_li <= 2 { + } else if timezone_len <= 2 { // -[0]3 let range_len = min(l[i + 1].len(), 2); hour_offset = Some(l[i + 1][..range_len].parse::()?); diff --git a/src/tests/fuzzing.rs b/src/tests/fuzzing.rs index 3626911..88048cf 100644 --- a/src/tests/fuzzing.rs +++ b/src/tests/fuzzing.rs @@ -111,6 +111,18 @@ fn github_36() { #[test] fn github_46() { - let parse_result = parse("2000-01-01 12:00:00+00:"); - assert!(parse_result.is_err()); + assert_eq!( + parse("2000-01-01 12:00:00+00:"), + Err(ParseError::TimezoneUnsupported) + ); + let parse_result = parse("2000-01-01 12:00:00+0811"); + match parse_result { + Ok((dt, offset)) => { + assert_eq!(format!("{:?}", dt), "2000-01-01T12:00:00".to_string()); + assert_eq!(format!("{:?}", offset), "Some(+08:11)".to_string()); + } + Err(_) => { + panic!(); + } + } }