Skip to content

fix: prevent numbers followed by letters from being parsed as timestamps#841

Open
mvanhorn wants to merge 1 commit intoivan-lednev:mainfrom
mvanhorn:osc/387-fix-time-parsing-false-positive
Open

fix: prevent numbers followed by letters from being parsed as timestamps#841
mvanhorn wants to merge 1 commit intoivan-lednev:mainfrom
mvanhorn:osc/387-fix-time-parsing-false-positive

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented Apr 9, 2026

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 the time pattern.

Testing

Verified with Node.js regex tests:

  • "250g sugar" - no match (was: matched as 2:50)
  • "15g salt" - no match (was: matched as 1:5? depending on backtrack)
  • "6 people" - no match
  • "10:30 meeting" - match (valid timestamp)
  • "6:00 dinner" - match (valid timestamp)
  • "2:50pm meeting" - match (valid timestamp with am/pm)

Fixes #387

This contribution was developed with AI assistance (Claude Code).

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
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.

Bullet list with leading number parsed as a task

1 participant