Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#67,102 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@helmipradita já está trabalhando nisso.

Desde 30/10/2026.

  • #67132 de @helmipradita — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript
Domínio
backend

Direção de pesquisa

Comece lendo src/node_dotenv.cc, especialmente Dotenv::ParseContent na linha citada na issue. Verifique os testes existentes sobre o comportamento de --env-file e util.parseEnv com uma entrada que começa com um BOM UTF-8. O trabalho estará concluído quando ambos os pontos de entrada analisarem a primeira chave sem o BOM e preservarem os valores esperados.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
JavaScript
Estrelas
123k
Forks
39.3k
Merge médio
4d 12h
PRs com merge (30d)
240

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de nodejs/node

Todas as issues de nodejs/node

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.