Skip to content

Reject negative, fractional and out-of-range numbers when encoding - #35

Merged
sc0Vu merged 1 commit into
web3p:masterfrom
sc0Vuai:fix/numeric-validation
Sep 23, 2026
Merged

sc0Vu merged 1 commit into
web3p:masterfrom
sc0Vuai:fix/numeric-validation

Conversation

@sc0Vuai

@sc0Vuai sc0Vuai commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

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.

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

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (1478705) to head (f2c2f17).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sc0Vu
sc0Vu merged commit 5def91e into web3p:master Sep 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants