fix: reject NaN widths in NominalWordWrap and clamp an unbounded width ratio [patch] - #146
Merged
Merged
Conversation
…h ratio [patch] A NaN wrap or glyph width failed both `<= 0` checks, and the NaN ratio cast to 0 and was clamped to one character per line. NaN now throws the documented ArgumentOutOfRangeException. The width ratio is now computed in double and clamped before the cast, so an infinite or huge ratio no longer becomes int.MinValue (and so one character per line) on targets before .NET 9, where float-to-int does not saturate. Fixes #143 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VwgZGoivWyqL4pWDsenTPm
…STEST0068) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VwgZGoivWyqL4pWDsenTPm
|
This was referenced Sep 29, 2026
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.



NominalWordWrapnow throwsArgumentOutOfRangeExceptionwhen either width isNaN, naming the parameter, as its docs say for any width that "is not greater than zero". Before this, NaN failed both<= 0checks, the ratio cast to 0, and the text came out one character per line.The width ratio is now computed in
doubleand clamped before the cast toint. An infinite or huge ratio therefore givesint.MaxValuecharacters per line (each input line stays whole) on every target. Before, net5–net8 and netstandard2.0 cast it toint.MinValuebecause float-to-int conversion does not saturate there, andMath.Max(1, …)turned that into one character per line.Tests
wrapWidthand a NaNnominalGlyphWidtheach throw with the rightParamName. Both fail with the fix reverted.wrapWidth = +Infinityandfloat.MaxValue / float.Epsilonkeep each input line whole.dotnet buildis clean on every target framework.Fixes #143
🤖 Generated with Claude Code
https://claude.ai/code/session_01VwgZGoivWyqL4pWDsenTPm
Generated by Claude Code