Skip to content

util: fix numericSeparator handling for scientific notation#62983

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

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

Conversation

@Fifixex

@Fifixex Fifixex commented Apr 27, 2026

Copy link
Copy Markdown

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

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (4e332e0) to head (019ec6e).
⚠️ Report is 370 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62983      +/-   ##
==========================================
+ Coverage   89.65%   89.68%   +0.02%     
==========================================
  Files         707      712       +5     
  Lines      219501   221251    +1750     
  Branches    42073    42389     +316     
==========================================
+ Hits       196803   198423    +1620     
- Misses      14587    14653      +66     
- Partials     8111     8175      +64     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 99.47% <100.00%> (-0.07%) ⬇️

... and 108 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.

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

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
@BridgeAR BridgeAR added the request-ci Add this label to start a Jenkins CI on a PR. label May 31, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 1, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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)

6 participants