Skip to content

validate digits in numeric string exponent - #79

Merged
nvms merged 1 commit into
nvms:mainfrom
vapebw:fix/numeric-string-exponent
Sep 13, 2026
Merged

nvms merged 1 commit into
nvms:mainfrom
vapebw:fix/numeric-string-exponent

Conversation

@vapebw

@vapebw vapebw commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

In php 8.x, strings with an exponent indicator (e/E) require at least one digit after the exponent or sign to be considered numeric strings. Strings like "0e", "1e", or "1e+" must be treated as non-numeric.

Previously, Value.isNumericString in src/runtime/value.zig consumed the exponent marker without verifying that digits followed this caused false numeric comparisons such as:

  • "0e" == 0 returning true
  • "1e" == "1" returning true
  • "0e" <=> "0" returning 0 instead of 1

While stdlib/types.zig's native is_numeric() already rejected these strings, Value.isNumericString() was missing the check

Solution

  • Require at least one digit after the exponent marker (e/E and optional +/-) in Value.isNumericString
  • Return false immediately if no exponent digits were consumed

Tests

  • Added unit tests in src/runtime/value.zig for valid and invalid exponent cases
  • Added parity test in tests/numeric_string_exponent.php matching native php 8.x behavior

@nvms nvms left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the bug against PHP 8.5 and ran the unit and compat suites on the branch. Thanks for the fix and the tests.

@nvms
nvms merged commit 35f1a63 into nvms:main Sep 13, 2026
20 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