Conversation
tcrypt25519
commented
Feb 14, 2026
- fix: Correctly validate month number.
- fix: Replace memory-hungry parse function.
Summary of ChangesHello @tcrypt25519, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the date parsing logic to improve performance and reduce memory usage by eliminating unnecessary heap allocations during string splitting. Additionally, it enhances data validation by introducing an explicit check for invalid month numbers when constructing Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR fixes two critical bugs in date parsing: adds missing month validation in Day::new() and replaces a memory-inefficient parsing implementation with a zero-allocation byte-by-byte parser.
Changes:
- Add month range validation (0 or >12) in
Day::new()to prevent invalid month values from being used in day-of-month calculations - Replace heap-allocating
parse_month_yearandparse_full_datefunctions with a single efficientparse_slash_datethat uses byte-by-byte parsing - Update tests to reflect the stricter parsing behavior (no whitespace around separators)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/types.rs | Adds month validation check in Day::new() before using month value for calculations |
| src/lib.rs | Replaces two separate parsing functions with unified parse_slash_date that avoids heap allocation and strictly validates format |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces two important fixes. First, it replaces a memory-intensive date parsing function with a more efficient, allocation-free byte-by-byte parser. This is a great performance improvement. Second, it adds a missing validation check for the month number in the Day::new constructor, improving the robustness of the type. The changes are well-implemented, but I've found a subtle bug in the new parse_slash_date function where it incorrectly slices the month string, which I've provided a fix for.
|
|
||
| Ok(Self::Month { year, month }) | ||
| } | ||
| let month_str = &s[..pos]; |
There was a problem hiding this comment.
There's a subtle bug here in how the month string is sliced. pos is currently the index of the / separator. Slicing with &s[..pos] correctly extracts the month digits. However, the pos variable is not updated to reflect the start of the month string, which is always 0. This can lead to incorrect parsing in some edge cases. To fix this, we should explicitly define the start of the month string.
| let month_str = &s[..pos]; | |
| let month_str = &s[0..pos-1]; |