Skip to content

Conversation

@BrynCooke
Copy link

@BrynCooke BrynCooke commented Oct 14, 2025

Fixes #1038

Summary

Fixes numeric parsing to support uppercase 'E' in scientific notation numbers (e.g., 1.23E4). this affects parse_json and regular rhai scripts.

This is particularly relevant to JSON parsing as uppercase E is allowed by the JSON spec, so currently valid JSON fails to parse.

Changes

  • Updated tokenizer to accept both 'e' and 'E' for exponent notation
  • Added unit tests for scientific notation parsing covering positive/negative exponents, uppercase/lowercase E, and edge cases.

bryn added 2 commits October 14, 2025 10:51
Add unit tests for parsing JSON numbers in scientific notation (e.g., 1.23e4,
1.5e-5). These tests currently fail, exposing a bug in the JSON parser where
scientific notation numbers are not properly recognized, causing parsing
errors when they appear in JSON object literals.

Tests cover:
- Positive exponents (1.23e4)
- Negative exponents (1.5e-5)
- Capital E notation (2.5E+10)
- Integer with exponent (3e2)
- Zero exponent (4.2e0)
The tokenizer now accepts both 'e' and 'E' for scientific notation in
floating-point numbers, making it properly compliant with JSON specification
which allows both forms (e.g., 1.23e4 and 1.23E4).

The fix changes the pattern match from just 'e' to 'ch @ ('e' | 'E')' and
uses the captured character when building the result string, preserving the
original case from the input.

This resolves the parsing failures in JSON numbers with uppercase 'E' exponents.
@BrynCooke BrynCooke changed the title Scientific notation (fix) parse_json uppercase exponent Oct 14, 2025
bryn added 2 commits October 14, 2025 12:53
Always convert uppercase 'E' to lowercase 'e' when building the number string
for parsing. This normalization simplifies float parsing since the string will
always use lowercase 'e' regardless of the input case.

The behavior remains the same - both 'E' and 'e' are accepted in input, but
internally we consistently use lowercase for parsing.
Add test cases for uppercase 'E' in scientific notation to the existing
test_float_scientific test. This ensures the fix works not just for JSON
parsing but for standard Rhai script evaluation as well.

Tests now cover both 'e' and 'E' variants:
- 1.23456E2
- 1.23456E+2
- 123456E-3
@BrynCooke BrynCooke changed the title (fix) parse_json uppercase exponent (fix) Support numeric uppercase exponent Oct 14, 2025
@schungx schungx merged commit a9e9099 into rhaiscript:main Oct 14, 2025
41 of 42 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.

parse_json fails to parse numbers with scientific notation using uppercase exponent

2 participants