You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
util.inspect incorrectly formats negative fractional numbers with numericSeparator: true #59376
How often does it reproduce? Is there a required condition?
Always reproducible for negative numbers strictly between -1 and 0, when numericSeparator: true is specified.
What is the expected behavior? Why is that the expected behavior?
The output should be syntactically valid JavaScript numeric literals representing the original values, with numeric separators inserted in accordance with the numericSeparator option. For the sample above, the expected output is::
For values where -1 < number < 0, this results in:
integer === -0 (correct)
string === '0' (loses the leading minus sign due to coercion)
addNumericSeparator(string) omits the minus sign from the formatted number
StringPrototypeSlice(String(number), string.length + 1) incorrectly retains the original decimal point, resulting in a duplicated dot (..) in the output
One potential fix would be to use logic similar to the non-numericSeparator case earlier in the function:
Activity
thoukydides commentedon Aug 6, 2025
I believe the bug is caused by the following
formatNumbercode inlib/internal/util/inspect.js:For values where
-1 < number < 0, this results in:integer === -0(correct)string === '0'(loses the leading minus sign due to coercion)addNumericSeparator(string)omits the minus sign from the formatted numberStringPrototypeSlice(String(number), string.length + 1)incorrectly retains the original decimal point, resulting in a duplicated dot (..) in the outputOne potential fix would be to use logic similar to the non-
numericSeparatorcase earlier in the function:However, a cleaner and more robust approach might be to either:
number < 0 || ObjectIs(number, -0); orHan5991 commentedon Aug 6, 2025
I'll give it a try?
BridgeAR commentedon Aug 6, 2025
I would either go with the quick fix suggested here or by performing the string conversion once.
@Han5991 go ahead. If you open a PR, please reference this issue with
Closes #59376.util: fix numericSeparator with negative fractional numbers
util: fix numericSeparator with negative fractional numbers
util: fix numericSeparator with negative fractional numbers
util: fix numericSeparator with negative fractional numbers