Skip to content

Commit ccd7f85

Browse files
committed
Allow 't' as a seperator between date and time in parse_rfc3339_relaxed
From the standard: > NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this syntax may > alternatively be lower case "t" or "z" respectively. The strict parser accepted 't', now the relaxed parser also does.
1 parent fb4371b commit ccd7f85

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/datetime/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ fn test_parse_datetime_utc() {
805805
"2001-02-03T04:05:06+0000",
806806
"2001-02-03T04:05:06-00:00",
807807
"2001-02-03T04:05:06-01:00",
808+
"2012-12-12 12:12:12Z",
809+
"2012-12-12t12:12:12Z",
808810
"2012-12-12T12:12:12Z",
809811
"2012 -12-12T12:12:12Z",
810812
"2012 -12-12T12:12:12Z",
@@ -871,7 +873,6 @@ fn test_parse_datetime_utc() {
871873
"2012-12-12T12:61:12Z", // invalid minute
872874
"2012-12-12T12:12:62Z", // invalid second
873875
"2012-12-12 T12:12:12Z", // space after date
874-
"2012-12-12t12:12:12Z", // wrong divider 't'
875876
"2012-12-12T12:12:12ZZ", // trailing literal 'Z'
876877
"+802701-12-12T12:12:12Z", // invalid year (out of bounds)
877878
"+ 2012-12-12T12:12:12Z", // invalid space before year

src/format/parse.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,14 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
567567
Err((_s, e)) => return Err(e),
568568
Ok(_) => return Err(NOT_ENOUGH),
569569
};
570-
if !(s.starts_with('T') || s.starts_with(' ')) {
571-
return Err(INVALID);
572-
}
573-
match parse_internal(parsed, &s[1..], TIME_ITEMS.iter()) {
570+
571+
s = match s.as_bytes().first() {
572+
Some(&b't' | &b'T' | &b' ') => &s[1..],
573+
Some(_) => return Err(INVALID),
574+
None => return Err(TOO_SHORT),
575+
};
576+
577+
match parse_internal(parsed, s, TIME_ITEMS.iter()) {
574578
Err((s, e)) if e.0 == ParseErrorKind::TooLong => Ok((s, ())),
575579
Err((_s, e)) => Err(e),
576580
Ok(s) => Ok((s, ())),

0 commit comments

Comments
 (0)