feat(clp-s::timestamp_parser): Add support for parsing RFC 2822 / 822 timestamp strings (fixes #2027).#2363
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR adds named timezone support via ChangesNamed Timezone Specifier
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…fc-822-timestamp-strings
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
components/core/src/clp_s/timestamp_parser/TimestampParser.cpp (1)
1175-1225: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
zandospecifiers silently overwrite each other's shared state.Both the
zcase (Line 1175-1199) and the newocase (Line 1200-1225) write to the singleoptional_timezone_size_and_offsetfield via.emplace(...).format_specifiersonly rejects a repeated occurrence of the same character, so a pattern combining both, e.g.\z{+0500} \o{EST,-0500}, is accepted bycreate, but the field ends up holding whichever specifier was parsed last.marshal_date_time_timestamp'szcase (Line 844-853) andocase (Line 854-867) both read from this same field, so whichever specifier was overwritten will emit/parse the wrong-length substring — silently corrupting the marshalled or parsed timestamp instead of failing.Add a check that rejects a pattern if
optional_timezone_size_and_offsetalready has a value when eitherzorois encountered.🐛 Suggested fix (apply to both `z` and `o` cases)
case 'o': { // Named time-zone with specific offset. + if (optional_timezone_size_and_offset.has_value()) { + return ErrorCode{ErrorCodeEnum::InvalidTimestampPattern}; + } auto const bracket_pattern{YSTDLIB_ERROR_HANDLING_TRYX(🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@components/core/src/clp_s/timestamp_parser/TimestampParser.cpp` around lines 1175 - 1225, The shared timezone state in TimestampParser::create is being overwritten when both the z and o specifiers appear in one pattern, because each case unconditionally emplaces into optional_timezone_size_and_offset. Update the z and o branches to reject a second timezone specifier by checking whether optional_timezone_size_and_offset already contains a value and returning InvalidTimestampPattern if so, so marshal_date_time_timestamp does not later read a corrupted size/offset pair.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@components/core/src/clp_s/timestamp_parser/TimestampParser.cpp`:
- Around line 1200-1225: The 'o' branch in TimestampParser::parse_pattern
accepts an empty named-timezone name because name_str is taken from the
bracketed pattern without validation. Add a check in the same handler, before
storing into optional_timezone_size_and_offset, to reject patterns where the
extracted name is empty (for example when comma_idx is immediately after the
opening brace) and return InvalidTimestampPattern. This should ensure
parse_timestamp’s 'o' matching logic cannot end up with an empty expected_name
and a no-op starts_with("") match.
- Around line 81-96: Store the timezone offset as a precomputed minute value in
NamedTimezone instead of keeping offset_str and re-parsing it in the Z handler.
Update the cNamedTimezones table and the matching logic in TimestampParser so
the named-zone branch uses the stored offset_minutes directly, avoiding repeated
extract_timezone_offset_in_minutes calls and the silent invalid-offset path.
---
Outside diff comments:
In `@components/core/src/clp_s/timestamp_parser/TimestampParser.cpp`:
- Around line 1175-1225: The shared timezone state in TimestampParser::create is
being overwritten when both the z and o specifiers appear in one pattern,
because each case unconditionally emplaces into
optional_timezone_size_and_offset. Update the z and o branches to reject a
second timezone specifier by checking whether optional_timezone_size_and_offset
already contains a value and returning InvalidTimestampPattern if so, so
marshal_date_time_timestamp does not later read a corrupted size/offset pair.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7dcdbb70-608f-44d1-8720-ead5e158f0a9
📒 Files selected for processing (3)
components/core/src/clp_s/timestamp_parser/TimestampParser.cppcomponents/core/src/clp_s/timestamp_parser/TimestampParser.hppcomponents/core/src/clp_s/timestamp_parser/test/test_TimestampParser.cpp
…eger values in TimestampParser
…to prevent parsing errors
…and add error handling tests
287d69d to
770449d
Compare
… for error reproduction
770449d to
dd04ded
Compare
…fc-822-timestamp-strings
gibber9809
left a comment
There was a problem hiding this comment.
Left an initial review for the whole PR.
Co-authored-by: Devin Gibson <gibber9809@users.noreply.github.com>
This reverts commit 97776bf.
…fc-822-timestamp-strings
…fc-822-timestamp-strings
…fc-822-timestamp-strings
Description
Adds support for parsing RFC 2822 / RFC 822 timestamp strings to the CLP-S timestamp parser.
\o{name,offset}specifier to handle named timezones.\Zto automatically recognize standard named timezones (like EST, PDT, etc).+0000offset.Also added tests and caught & fixed a bug: the timestamp parser throws an
IncompatibleTimestampPatternerror when using\Zto parse a string ending in"UTC"without any trailing offset (e.g., parsing"01 Jan 2000 00:00:00 UTC"against pattern\d \B{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec} \Y \H:\M:\S \Z). This is fixed by addingoptional_timezone_offset_in_minutes = 0;to thecUtchandling block.Checklist
breaking change.
Validation performed
Added unit tests to test_TimestampParser.cpp verifying the \o specifier, \Z fallback logic, and full RFC 2822 formatting strings.
Summary by CodeRabbit
ospecifier (\o{name,offset}).