mirror of
https://github.com/stalwartlabs/mail-parser.git
synced 2026-12-04 08:01:42 +00:00
Accept lower-case 't' separator in RFC 3339 dates (#174)
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [1.0.4] - Unreleased
|
||||
|
||||
### Fixed
|
||||
- `DateTime::parse_rfc3339` returned `None` for a date with a lower-case `t` separator, such as `2021-11-20t14:22:01Z`, which RFC 3339 allows (#174).
|
||||
|
||||
## [1.0.3] - 2026-11-29
|
||||
|
||||
### Fixed
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "mail-parser"
|
||||
description = "Fast and robust e-mail parsing library for Rust"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
edition = "2024"
|
||||
rust-version = "1.98"
|
||||
authors = [ "Stalwart Labs <hello@stalw.art>"]
|
||||
|
||||
+23
-2
@@ -72,14 +72,14 @@ impl DateTime {
|
||||
is_plus = false;
|
||||
skip_digits = false;
|
||||
}
|
||||
b'T' if pos == 2 => pos += 1,
|
||||
b'T' | b't' if pos == 2 => pos += 1,
|
||||
b':' if matches!(pos, 3 | 4 | 6) => pos += 1,
|
||||
b'+' if pos == 5 => {
|
||||
pos += 1;
|
||||
skip_digits = false;
|
||||
}
|
||||
b'.' if pos == 5 => skip_digits = true,
|
||||
b'-' | b'T' | b':' | b'+' | b'.' => return None,
|
||||
b'-' | b'T' | b't' | b':' | b'+' | b'.' => return None,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -290,6 +290,27 @@ mod tests {
|
||||
assert!(DateTime::parse_rfc3339("2004-06-28+23:43:45").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc3339_lower_case_t_and_z() {
|
||||
// Lower-case "t" and "z" parse like the upper-case forms (RFC 3339 section 5.6).
|
||||
let upper = DateTime::parse_rfc3339("2021-11-20T14:22:01Z").expect("valid");
|
||||
for input in [
|
||||
"2021-11-20t14:22:01Z",
|
||||
"2021-11-20T14:22:01z",
|
||||
"2021-11-20t14:22:01z",
|
||||
] {
|
||||
assert_eq!(DateTime::parse_rfc3339(input), Some(upper), "{input}");
|
||||
}
|
||||
// Lower-case "t" with an explicit offset.
|
||||
assert_eq!(
|
||||
DateTime::parse_rfc3339("2021-11-20t14:22:01-08:00").map(|d| d.to_rfc3339()),
|
||||
Some("2021-11-20T14:22:01-08:00".to_string())
|
||||
);
|
||||
// A misplaced "t" is rejected like a misplaced "T".
|
||||
assert!(DateTime::parse_rfc3339("2021t11-20T14:22:01Z").is_none());
|
||||
assert!(DateTime::parse_rfc3339("2021-11-20T14:22:01t").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timestamps() {
|
||||
let date = DateTime::parse_rfc3339("2021-11-20T14:22:01-08:00").expect("valid");
|
||||
|
||||
Reference in New Issue
Block a user