Skip to content

util: fix numericSeparator handling for scientific notation#62983

Open
Fifixex wants to merge 2 commits intonodejs:mainfrom
Fifixex:fix-inspect-numeric-separator
Open

util: fix numericSeparator handling for scientific notation#62983
Fifixex wants to merge 2 commits intonodejs:mainfrom
Fifixex:fix-inspect-numeric-separator

Conversation

@Fifixex
Copy link
Copy Markdown

@Fifixex Fifixex commented Apr 27, 2026

This commit fixes incorrect behavior in util.inspect when numericSeparator is enabled and the input number is represented in scientific notation (e.g. 1e-7 or 1e+21).

Previously, scientific notation strings were incorrectly processed by the numeric separator logic, which assumes the presence of a decimal point. This led to malformed output such as:

'1e-.1e-_7'

The issue occurs because the formatting logic attempts to split the numeric string at a decimal point (.), which does not exist in scientific notation. As a result, incorrect string slicing is applied. This change adds a guard for scientific notation strings, ensuring they are returned without applying numeric separator formatting. It also fixes the case where no decimal point exists by treating the value as a plain number string.

Closes: #62981

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Apr 27, 2026
@ljharb ljharb requested a review from BridgeAR April 27, 2026 05:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (4e332e0) to head (a700075).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/util/inspect.js 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62983      +/-   ##
==========================================
- Coverage   89.65%   89.65%   -0.01%     
==========================================
  Files         707      707              
  Lines      219501   219504       +3     
  Branches    42073    42084      +11     
==========================================
- Hits       196803   196799       -4     
- Misses      14587    14591       +4     
- Partials     8111     8114       +3     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 99.44% <25.00%> (-0.10%) ⬇️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM with my comment being addressed

Comment thread lib/internal/util/inspect.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util.inspect: incorrect numericSeparator formatting for numbers in scientific notation (e.g. 1e-7)

5 participants