util.parseEnv and --env-file keep a leading UTF-8 BOM in the first key
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 78/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript
- 領域
- backend
研究方向
先閱讀 src/node_dotenv.cc,尤其是 issue 中引用行的 Dotenv::ParseContent。檢查現有測試中 --env-file 和 util.parseEnv 對以 UTF-8 BOM 開頭的輸入的處理行為。完成標準是兩個入口都能解析不含 BOM 的第一個鍵,並保留預期值。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- JavaScript
- 星號
- 123k
- 分支
- 39.3k
- 平均合併
- 4 天 16 小時
- 30 天內合併 PR
- 227
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
http2: content-encoding is incorrectly listed in kSingleValueHeaders可能已有人在做 @inoway46 於 1 天前認領。 未關閉confirmed-bug http2
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
node:internal/inspector/network_http: `TypeError: Missing dataLength` in event when response uses `setEncoding()`可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already exist可能已有人在做 @Sepandard 於 37 天前認領。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
Stream.prototype.forEach will block in first promise in queue before read more chunk可能已有人在做 @mmustafasenoglu 於 38 天前認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
nodejs 26.8.2 fails to build with clang/LLVM可能重新可做 @btyagi18 於 24 天前認領,目前沒有進行中的 PR。 未關閉build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 72/100
mongoosejs/mquery#142 ·
-
難度 1/5 1 小時以內 新手友好度 65/100
維護者通常 1 天內回覆
-
Add toro4n to the data modeling tools可能已有人在做 @henriklantzhedstrom-prog 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 62/100
neo4j/docs-getting-started#546 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 25 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
libnativeapi/nativeapi#21 ·