Skip to content

fix(Foundation): Reject trailing garbage in DateTimeParser (#5030)#5117

Merged
matejk merged 2 commits intomainfrom
5030-datetime-parser-trailing-garbage
Dec 18, 2025
Merged

fix(Foundation): Reject trailing garbage in DateTimeParser (#5030)#5117
matejk merged 2 commits intomainfrom
5030-datetime-parser-trailing-garbage

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Dec 17, 2025

Summary

Fixes #5030 - DateTimeParser now properly rejects input strings with unconsumed trailing characters.

Problem

DateTimeParser::parse() and tryParse() were accepting invalid input strings that didn't match the format:

// These incorrectly returned true / didn't throw:
tryParse("%H:%M", "12345", ...)  // parsed as 12:34, ignored trailing '5'
tryParse("????", "12345", ...)   // no format specifiers, ignored all input

Solution

After consuming all format specifiers, the parser now:

  1. Skips trailing whitespace in the input
  2. Throws SyntaxException if any non-whitespace characters remain

The fix maintains backwards compatibility by keeping the lenient literal character matching (format literals that don't match input are skipped), which existing code relies on.

Changes

Test Results

All existing tests pass, plus the new issue-specific tests:

  • "%H:%M" with "13:13" → success ✓
  • "%H:%M" with "xxx" → failure ✓
  • "%H:%M" with "12345" → failure (trailing garbage) ✓
  • "????" with "12345" → failure (invalid format) ✓

@matejk
Copy link
Copy Markdown
Contributor Author

matejk commented Dec 18, 2025

Test Fix Details

The test failures (testSQLChannel and testSQLLogger) were caused by a schema mismatch, not by the DateTimeParser fix itself.

Root Cause

The tests created tables with DateTime DATE column type, but SQLChannel stores full ISO8601 timestamps (e.g., "2025-12-18T07:39:36Z") via the Binder.

When extracting from a DATE column:

  • SQLite Extractor uses SQLITE_DATE_FORMAT = "%Y-%m-%d" (date-only)
  • But the stored value is full ISO8601 format "%Y-%m-%dT%H:%M:%S%z"
  • Before this PR: parser silently ignored trailing "T07:39:36Z"
  • After this PR: parser correctly rejects it as garbage

Fix

Changed column type from DATE to DATETIME in:

  • SQLiteTest::testSQLChannel() (3 tables)
  • SQLiteTest::testSQLLogger() (1 table)
  • DBLogger sample (1 table)

This ensures the column type matches what's being stored. DATETIME columns use auto-detection parsing which correctly handles full ISO8601 format.

The DateTimeParser fix exposed a pre-existing schema bug in the tests.

@matejk matejk merged commit 8410eb1 into main Dec 18, 2025
85 of 86 checks passed
@matejk matejk deleted the 5030-datetime-parser-trailing-garbage branch January 15, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Foundation: DateTimeParser accepts trailing garbage

1 participant