Skip to content

Conversation

@djc
Copy link
Member

@djc djc commented Sep 8, 2025

Fixes #1725.

@djc djc requested a review from Copilot September 8, 2025 08:45
Copy link

Copilot AI left a 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 error method 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
Copy link

Copilot AI Sep 8, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
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()]),
Copy link

Copilot AI Sep 8, 2025

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.

Suggested change
true => Item::Literal(&original[..original.len() - remainder.len()]),
true => Item::Literal(
original.strip_suffix(remainder).unwrap_or(""),
),

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 94.69697% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.88%. Comparing base (757a8b0) to head (30e8399).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/format/strftime.rs 94.69% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@djc djc merged commit f3fd15f into main Sep 8, 2025
35 checks passed
@djc djc deleted the finite-items branch September 8, 2025 08:59
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.

StrftimeItems returns never-ending iterator.

2 participants