nodejs / nodejs/node

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

Aperta
#62,981 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

never-stale
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso util.inspect e riproduci l’esempio fornito di numericSeparator usando Node.js. Segui il percorso di formattazione per la notazione scientifica e verifica che il risultato rimanga una stringa numerica valida; aggiungi una copertura di regressione sia per 1e-7 sia per 1e+21 se i test circostanti forniscono una posizione adatta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
66/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.