-
Notifications
You must be signed in to change notification settings - Fork 593
strftime: simplify error handling #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies error handling in the strftime module by refactoring the error handling logic to be more straightforward and adding a regression test for issue #1725.
- Simplified error handling by refactoring the
errormethod to use cleaner parameter passing - Restructured code organization by moving static constants and the Iterator implementation to the end of the file
- Added a regression test to prevent infinite loops in strftime parsing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/format/strftime.rs | Refactored error handling logic, reorganized code structure, and added regression test |
| Cargo.toml | Version bump from 0.4.41 to 0.4.42 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| remainder = &remainder[x.len_utf8()..]; | ||
| x | ||
| } | ||
| None => return Some((remainder, self.error(original, remainder))), // premature end of string |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling logic is incorrect. When there's a premature end of string, remainder is empty, but the error method expects the remaining string to calculate the consumed portion. This should pass an empty string slice or handle the case differently.
| None => return Some((remainder, self.error(original, remainder))), // premature end of string | |
| None => return Some((&original[original.len()..], self.error(original, &original[original.len()..]))), // premature end of string |
| fn error<'b>(&mut self, original: &'b str, remainder: &'b str) -> Item<'b> { | ||
| match self.lenient { | ||
| false => Item::Error, | ||
| true => Item::Literal(&original[..original.len() - remainder.len()]), |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error method calculation original.len() - remainder.len() can panic if remainder is not a substring of original or if there are UTF-8 boundary issues. This should use proper string slicing methods that account for the relationship between the strings.
| true => Item::Literal(&original[..original.len() - remainder.len()]), | |
| true => Item::Literal( | |
| original.strip_suffix(remainder).unwrap_or(""), | |
| ), |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1731 +/- ##
==========================================
+ Coverage 90.79% 90.88% +0.08%
==========================================
Files 39 39
Lines 16254 16223 -31
==========================================
- Hits 14758 14744 -14
+ Misses 1496 1479 -17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #1725.