fix: prevent numbers followed by letters from being parsed as timestamps#841
Open
mvanhorn wants to merge 1 commit intoivan-lednev:mainfrom
Open
fix: prevent numbers followed by letters from being parsed as timestamps#841mvanhorn wants to merge 1 commit intoivan-lednev:mainfrom
mvanhorn wants to merge 1 commit intoivan-lednev:mainfrom
Conversation
Add a negative lookahead (?!\w) to the time regex so that strings like
"250g sugar" or "15g salt" are no longer falsely matched as timestamps.
The regex was backtracking: for "250g", \d{1,2} matched "2" and \d{2}
matched "50", ignoring the trailing "g". The lookahead ensures the
matched time is not followed by a word character.
Fixes ivan-lednev#387
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bullet list items containing numbers followed by letters (e.g. "250g sugar", "15g salt") are no longer falsely parsed as timestamps and added to the timeline.
Why this matters
The time regex was backtracking on inputs like "250g":
\d{1,2}matched "2" and\d{2}matched "50", treating it as 2:50. The trailing "g" was ignored.Adding
(?!\w)after the time pattern ensures the matched timestamp is not part of a larger word.Changes
src/regexp.ts: Added negative lookahead(?!\w)to thetimepattern.Testing
Verified with Node.js regex tests:
Fixes #387
This contribution was developed with AI assistance (Claude Code).