8000 fix(temporal): avoid byte-index panic on non-UTF-8-boundary input by adityamukho · Pull Request #325 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(query [:::as-of"f[r[Y[[r[؅f"n_1])
10 changes: 9 additions & 1 deletion src/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use chrono::{DateTime, NaiveDate, TimeZone, Utc};
/// - Any string with a timezone offset (e.g., `+05:30`) — use UTC (Z) only.
pub fn parse_timestamp(s: &str) -> Result<i64> {
// Reject timezone offsets explicitly
if s.contains('+') || (s.len() > 10 && s[10..].contains('-')) {
if s.contains('+') || s.get(10..).is_some_and(|rest| rest.contains('-')) {
return Err(anyhow!(
"timezone offsets are not supported; use UTC (Z) timestamps only. \
chrono's local timezone handling (GHSA-wcg3-cvx6-7396) is avoided by design."
Expand Down Expand Up @@ -91,6 +91,14 @@ mod tests {
assert!(parse_timestamp("not-a-date").is_err());
}

#[test]
fn test_multibyte_char_near_byte_offset_10_does_not_panic() {
// Byte offset 10 falls inside the 2-byte UTF-8 encoding of '\u{605}',
// which starts at byte 9. Slicing s[10..] would panic on a non-char-boundary.
let s = "123456789\u{605}abc";
assert!(parse_timestamp(s).is_err());
}

#[test]
fn test_millis_to_timestamp_roundtrip() {
let original = "2024-01-15T10:00:00Z";
Expand Down
Loading
0