Repository navigation
Reject a sub-tick --for and report an overflowing one as too long [patch] - #59
Merged
Merged
Conversation
…tch] TryParseAnyLength checked that the duration was positive on the double, before TimeSpan.FromSeconds rounded "0.00000001s" down to zero, so the tool started and stopped at once. It also returned false for a value past TimeSpan.MaxValue, so "--for 20000000d" was reported as "not a duration" rather than "too long". Check the converted TimeSpan for at least one tick, and return TimeSpan.MaxValue for a value too long to hold so the caller's upper bound reports it. Fixes #57 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3e2AZDcKPKkvjAga2
TimeSpan.FromSeconds does not throw for any value below the TimeSpan.MaxValue.TotalSeconds guard that precedes it (it does not throw at the bound itself either), so the catch was dead code and left the new lines short of the coverage gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3e2AZDcKPKkvjAga2
|
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.



Fixes #57
What was wrong
DurationParser.TryParseAnyLengthcheckedtotalSeconds <= 0and> TimeSpan.MaxValue.TotalSecondson thedouble, before converting it:--for 0.00000001spassed the positive check, thenTimeSpan.FromSecondsrounded it toTimeSpan.Zero. The tool started and stopped at the same moment, and the tray timer got a zero interval.--for 20000000dreturnedfalse, soCommandLineParser.ReadDurationreported it as "not a duration" instead of the "too long" message that30dgets.Change
TimeSpanmust be at least one tick, so a sub-tick value is rejected as not a duration.TimeSpancomes back asTimeSpan.MaxValue. The existing> MaxDurationchecks inTryParseandReadDurationthen reject it as too long. The publicTryParsecontract is unchanged.Tests
DurationParserTests:0.00000001s/0.00000004sare invalid.20000000dand a 68-digit hour count are too long forTryParseand come back asTimeSpan.MaxValuefromTryParseAnyLength.CommandLineParserTests:--for 0.00000001sgives "is not a duration", and--for 20000000dgives "--for can be at most 24 days".mainand pass with the fix. Full suite: 170 passed, 1 skipped, 0 failed.Generated by Claude Code