Skip to content

util.inspect incorrectly formats negative fractional numbers with numericSeparator: true #59376

@thoukydides

Description

@thoukydides

Version

v24.5.0 (also reproduced on v20.19.2)

Platform

Linux nexus 6.14.0-27-generic #27~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 17:38:49 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

util

What steps will reproduce the bug?

import { inspect } from 'util';

const values = [0.1234, -0.12, -0.123, -0.1234, -1.234];
const text = inspect(values, { numericSeparator: true });
console.log(text);

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::

[ 0.123_4, -0.12, -0.123, -0.123_4, -1.234 ]

What do you see instead?

The actual output of the sample script is:

[ 0.123_4, 0..12, 0..12_3, 0..12_34, -1.234 ]

The three incorrect values:

  • Are missing their leading minus sign
  • Contain a spurious double decimal point (0..)
  • Place the numeric separator incorrectly

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions