Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

util.parseEnv and --env-file keep a leading UTF-8 BOM in the first key

Offen Anfängerfreundlich
#67,102 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@helmipradita arbeitet bereits daran.

Seit 30.10.2026.

  • #67132 von @helmipradita — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript
Bereich
backend

Rechercherichtung

Lies zuerst src/node_dotenv.cc, insbesondere Dotenv::ParseContent an der im Issue angegebenen Zeile. Prüfe die vorhandenen Tests zum Verhalten von --env-file und util.parseEnv bei Eingaben, die mit einem UTF-8-BOM beginnen. Das Ziel ist erreicht, wenn beide Einstiegspunkte den ersten Schlüssel ohne BOM parsen und die erwarteten Werte beibehalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Version

v24.18.0 (the code is the same on main)

Platform

Windows 11 x64 (not platform-specific; the file bytes are what matter)

Subsystem

dotenv (--env-file, util.parseEnv)

What steps will reproduce the bug?
printf '\xef\xbb\xbfA=1\r\nB=2\r\n' > .env
node --env-file=.env -e "console.log(process.env.A, process.env.B)"
node -e "console.log(require('util').parseEnv('A=1\nB=2'))"

Such files are common on Windows: PowerShell 5.1 Set-Content -Encoding utf8 / Out-File -Encoding utf8 and Notepad's "UTF-8 with BOM" write a leading EF BB BF.

How often does it reproduce? Is there a required condition?

Always, when the file starts with a UTF-8 BOM.

What is the expected behavior? Why is that the expected behavior?

1 2 and { A: '1', B: '2' }: the BOM is an encoding marker, not part of the first key. The dotenv package returns { A: '1', B: '2' } for the same bytes, and Node already skips a BOM when loading CommonJS/ESM sources and JSON.

What do you see instead?
undefined 2
{ B: '2', 'A': '1' }

The first variable is silently lost under its real name.

Additional information

Dotenv::ParseContent (src/node_dotenv.cc:147) strips \r but not a leading BOM, so it stays in the first key. Skipping a leading \xEF\xBB\xBF at the start of the input there would fix both --env-file and util.parseEnv. This also affects tools that moved to util.parseEnv, e.g. Vite's .env loading.

Vorherrschende Sprache
JavaScript
Sterne
123k
Forks
39.3k
Ø Merge
4 T. 12 Std.
Gemergte PRs (30 T.)
240

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nodejs/node

Alle Issues in nodejs/node

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.