You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: reject out-of-range integral cell values - #1101
Integer converters and NumberUtils.parseByte/parseShort/parseInteger/parseLong now range-check the value before narrowing, so out-of-range values throw instead of wrapping around.
The integer parse* methods now call parseBigDecimal, which already has the hasFormat branch.
Added out-of-range tests to ConverterTest and NumberUtilsTest.
Reviewed the diff - the approach looks right: checkRange truncates toward zero first (so fractional values keep narrowing the way they did before intValueExact-style strictness would allow) and only the truncated integral part is range-checked, which matches the semantics I had implemented in the now-closed #1188.
One suggestion: add a fraction-truncation regression test (e.g. parseInteger("123.9") == 123 and the same for a NUMBER cell on IntegerNumberConverter). Nothing in the current tests pins that behavior, and it protects the narrowing semantics from being "exactified" by a future refactor.
Reviewed the diff - the approach looks right: checkRange truncates toward zero first (so fractional values keep narrowing the way they did before intValueExact-style strictness would allow) and only the truncated integral part is range-checked, which matches the semantics I had implemented in the now-closed #1188.
One suggestion: add a fraction-truncation regression test (e.g. parseInteger("123.9") == 123 and the same for a NUMBER cell on IntegerNumberConverter). Nothing in the current tests pins that behavior, and it protects the narrowing semantics from being "exactified" by a future refactor.
Thanks, the fraction case is already pinned: test_parseInteger_noFormat_truncatesFraction and the 42.9 assertion in ConverterTest cover it, and test_toInt_bounds covers the 2147483647.9 / -2147483648.9 boundary that a stricter refactor would break. I'd rather not add a near-duplicate 123.9 test.
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
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.
Closed: #1100
Purpose of the pull request
As title.
What's changed?
NumberUtils.parseByte/parseShort/parseInteger/parseLongnow range-check the value before narrowing, so out-of-range values throw instead of wrapping around.parse*methods now callparseBigDecimal, which already has thehasFormatbranch.ConverterTestandNumberUtilsTest.Checklist