nodejs / nodejs/node

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

オープン
#62,981 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

never-stale
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v24.14.0

Platform
Linux DESKTOP-59R7A1D 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025 x86_64 GNU/Linux
Subsystem

util.inspect

What steps will reproduce the bug?
const util = require('util');

console.log(util.inspect(1e-7, { numericSeparator: true }));
How often does it reproduce? Is there a required condition?

Always reproducible when:

  • numericSeparator is set to true
  • The number is formatted using scientific notation (e.g. 1e-7, 1e+21)
What is the expected behavior? Why is that the expected behavior?

The output should remain a valid numeric string representation.

For example:

'1e-7'

Scientific notation should either:

  • remain unchanged, or
  • be properly expanded before applying numeric separators

But it should never produce malformed output.

What do you see instead?

Malformed and corrupted output:

'1e-.1e-_7'

This happens because the formatting logic assumes that any non-integer number contains a decimal point (.), and attempts to split the string accordingly. However, scientific notation strings like '1e-7' do not contain a decimal point, leading to incorrect string slicing and separator insertion.

Additional information

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

util.inspect のエントリポイントから始め、Node.js を使用して、提示された numericSeparator の例を再現します。指数表記のフォーマット処理を追跡し、結果が有効な数値文字列のままであることを確認します。周辺のテストに適切な場所がある場合は、1e-7 と 1e+21 の両方に対するリグレッションカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
66/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。