Skip to content

Commit

Permalink
Allow 't' as a seperator between date and time in `parse_rfc3339_rela…
Browse files Browse the repository at this point in the history
…xed`

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.
  • Loading branch information
pitdicker committed Aug 29, 2023
1 parent fb4371b commit ccd7f85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ fn test_parse_datetime_utc() {
"2001-02-03T04:05:06+0000",
"2001-02-03T04:05:06-00:00",
"2001-02-03T04:05:06-01:00",
"2012-12-12 12:12:12Z",
"2012-12-12t12:12:12Z",
"2012-12-12T12:12:12Z",
"2012 -12-12T12:12:12Z",
"2012 -12-12T12:12:12Z",
Expand Down Expand Up @@ -871,7 +873,6 @@ fn test_parse_datetime_utc() {
"2012-12-12T12:61:12Z", // invalid minute
"2012-12-12T12:12:62Z", // invalid second
"2012-12-12 T12:12:12Z", // space after date
"2012-12-12t12:12:12Z", // wrong divider 't'
"2012-12-12T12:12:12ZZ", // trailing literal 'Z'
"+802701-12-12T12:12:12Z", // invalid year (out of bounds)
"+ 2012-12-12T12:12:12Z", // invalid space before year
Expand Down
12 changes: 8 additions & 4 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,14 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
Err((_s, e)) => return Err(e),
Ok(_) => return Err(NOT_ENOUGH),
};
if !(s.starts_with('T') || s.starts_with(' ')) {
return Err(INVALID);
}
match parse_internal(parsed, &s[1..], TIME_ITEMS.iter()) {

s = match s.as_bytes().first() {
Some(&b't' | &b'T' | &b' ') => &s[1..],
Some(_) => return Err(INVALID),
None => return Err(TOO_SHORT),
};

match parse_internal(parsed, s, TIME_ITEMS.iter()) {
Err((s, e)) if e.0 == ParseErrorKind::TooLong => Ok((s, ())),
Err((_s, e)) => Err(e),
Ok(s) => Ok((s, ())),
Expand Down

0 comments on commit ccd7f85

Please sign in to comment.