nodejs / nodejs/node

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

未关闭
#62,981 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

never-stale
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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 摘要。