Skip to content

Commit

Permalink
Remove hack to accept "UTC" in timezone_offset_zulu
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Aug 28, 2023
1 parent 814d17b commit a02d495
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
19 changes: 13 additions & 6 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
Item::Numeric(Numeric::Second, Pad::Zero),
Item::Fixed(Fixed::Nanosecond),
Item::Space(""),
Item::Fixed(Fixed::TimezoneOffsetZ),
];

s = match parse_internal(parsed, s, DATE_ITEMS.iter()) {
Expand All @@ -574,11 +573,19 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
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, ())),
}
s = match parse_internal(parsed, s, TIME_ITEMS.iter()) {
Err((s, e)) if e.0 == ParseErrorKind::TooLong => s,
Err((_s, e)) => return Err(e),
Ok(_) => return Err(NOT_ENOUGH),
};
s = s.trim_start();
let (s, offset) = if s.starts_with("UTC") || s.starts_with("utc") {
(&s[3..], 0)
} else {
scan::timezone_offset(s, scan::colon_or_space, true, false, true)?
};
parsed.set_offset(i64::from(offset))?;
Ok((s, ()))
}

#[cfg(test)]
Expand Down
17 changes: 2 additions & 15 deletions src/format/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,8 @@ where
F: FnMut(&str) -> ParseResult<&str>,
{
if allow_zulu {
let bytes = s.as_bytes();
match bytes.first() {
Some(&b'z') | Some(&b'Z') => return Ok((&s[1..], 0)),
Some(&b'u') | Some(&b'U') => {
if bytes.len() >= 3 {
let (b, c) = (bytes[1], bytes[2]);
match (b | 32, c | 32) {
(b't', b'c') => return Ok((&s[3..], 0)),
_ => return Err(INVALID),
}
} else {
return Err(INVALID);
}
}
_ => {}
if let Some(&b'Z' | &b'z') = s.as_bytes().first() {
return Ok((&s[1..], 0));
}
}

Expand Down

0 comments on commit a02d495

Please sign in to comment.