Repository navigation
fix: trailing decimal point drops the following unit - #74
Merged
dy merged 1 commit intoSep 28, 2026
Merged
Conversation
A number like "5." (integer part followed by a bare decimal point with
no fraction digits) failed the number regex's decimal branch, which
requires at least one digit after the dot. The engine then matched
just "5" with an empty unit capture, so the term fell back to the
base format (ms) instead of picking up the unit that followed the
dot.
parse('5. seconds') returned 5 instead of 5000, silently disagreeing
with parse('5 seconds'). The existing test for this shape used a
zero value ('+0. secs' => 0), which passes either way and hid the bug.
Made the fractional part of the digit-first branch accept zero
digits after the dot, so "5." is consumed as part of the number and
the trailing unit is captured correctly. Added regression tests
covering a space and no space before the unit, and a negative value.
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.
The number regex's decimal branch is
\d+(?:\.\d+)?, which requires at least one digit after a decimal point. If a number is written with a trailing dot and no fraction digits (5.), that branch fails, so only the bare digits (5) match and the dot is left dangling. Since the unit capture group has to sit immediately after the number match, the dot in between breaks the adjacency and the unit gets captured as empty. The term then falls back to the base format (ms) instead of the unit that was actually written.There's already a test for this shape (
'+0. secs'=>0), but it uses a zero value, so it can't tell the difference between the unit being applied correctly and the unit being dropped, since0 * anythingis0either way. That's what let this slip through.Fix: let the fractional part of the digit-first branch match zero digits (
\d+(?:\.\d*)?), so a trailing.is consumed as part of the number instead of left over to break the unit match. The lone-dot branch (\.\d+, for.5-style values) is untouched, so a bare.on its own still isn't treated as a number.Added a test block covering both a spaced and unspaced trailing dot, plus a negative value, and confirmed it fails against the old regex and passes with the fix. Full existing suite (102 cases) still passes, now 106 with the new ones.