Reject negative, fractional and out-of-range numbers when encoding - #35
Merged
Merged
Conversation
Numeric::encode silently encoded negative numbers as zero (-1 -> 80), truncated fractional floats (1.5 -> 01), and crashed with a TypeError for floats written in exponent form (1e15, 1e20), INF, NAN and non-numeric strings. Accept only non-negative integers up to PHP_INT_MAX (including integral floats such as 1024.0 and 1e15) and throw InvalidArgumentException otherwise. Larger values should be passed as hex strings. Remove the unreachable number_format branch. Replace the testIssue14 assertions that expected -1/-2 to encode as 80 and add valid/invalid numeric vectors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #35 +/- ##
============================================
+ Coverage 94.44% 95.29% +0.84%
- Complexity 61 66 +5
============================================
Files 3 3
Lines 162 170 +8
============================================
+ Hits 153 162 +9
+ Misses 9 8 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Numeric::encode silently encoded negative numbers as zero (-1 -> 80), truncated fractional floats (1.5 -> 01), and crashed with a TypeError for floats written in exponent form (1e15, 1e20), INF, NAN and non-numeric strings.
Accept only non-negative integers up to PHP_INT_MAX (including integral floats such as 1024.0 and 1e15) and throw InvalidArgumentException otherwise. Larger values should be passed as hex strings. Remove the unreachable number_format branch.
Replace the testIssue14 assertions that expected -1/-2 to encode as 80 and add valid/invalid numeric vectors.