util.inspect: fix numericSeparator for scientific notation numbers#62987
util.inspect: fix numericSeparator for scientific notation numbers#62987AmSach wants to merge 2 commits intonodejs:mainfrom
Conversation
| return base; | ||
| return ctx.stylize(base, StringPrototypeToLowerCase(type)); | ||
| if (constructor !== null) { | ||
| const superName = ObjectGetPrototypeOf(value).name; |
There was a problem hiding this comment.
why would a [[Prototype]] object necessarily have a .name? and why would a class-related change belong in a PR fixing number display?
| ctx.indentationLvl += 2; | ||
| let i = 0; | ||
| ctx.indentationLvl += 2; |
AmSach
left a comment
There was a problem hiding this comment.
Thanks for the review. You're right that tests are needed - I'll add comprehensive test cases for numericSeparator with scientific notation numbers.
Regarding the unrelated changes (prototype extension logic at lines 1541-1554, and the StringPrototypeIncludes -> StringPrototypeSlice change at line 1837): those are oversights from an auto-formatting or IDE action that shouldn't have been committed. I'll revert those and keep only the numericSeparator fix.
I'll also remove the duplicate StringPrototypeIncludes(numberString, 'e') checks at lines 2211-2214 and 2222-2225 - those are redundant.
When numericSeparator: true is set, util.inspect produces corrupted output like '1e-.1e-_7' for numbers in scientific notation. The fix adds an early return in formatNumber() for scientific notation numbers (containing 'e') before the decimal-split + numeric separator logic runs. Fixes nodejs#62981
c4cb7e2 to
167e59e
Compare
|
(note this is also a duplicate of #62983) |
Move the scientific notation check to the start of formatNumber() to fix corrupted output like '1e-.1e-_7' instead of '1e-7'. Previously the check was placed AFTER integer === number which caused it to be checked too late in the flow, allowing scientific notation numbers to reach the numeric separator logic incorrectly. Also adds comprehensive test cases for scientific notation with numericSeparator: true covering various exponent formats. Fixes nodejs#62981
Fixes #62981
When numericSeparator: true is set, util.inspect produces corrupted output like '1e-.1e-_7' for numbers in scientific notation (e.g. 1e-7).
The fix adds an early return for scientific notation strings before the decimal-split + numeric separator logic runs.