Accept lower-case 't' separator in RFC 3339 dates (#174)

This commit is contained in:
Amal Saidov
2026-12-03 11:01:46 +01:00
committed by GitHub
parent e4163efe77
commit 5620763609
3 changed files with 29 additions and 3 deletions
+5
View File
@@ -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
View File
@@ -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
View File
@@ -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");