Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ void Dotenv::ParseContent(const std::string_view input) {
lines.erase(std::remove(lines.begin(), lines.end(), '\r'), lines.end());

std::string_view content = lines;

// Strip leading UTF-8 Byte Order Mark (BOM) if present
if (content.rfind("\xEF\xBB\xBF", 0) == 0) {
content = content.substr(3);
}

content = trim_spaces(content);

std::string_view key;
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-util-parse-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const fs = require('node:fs');
assert.deepStrictEqual(util.parseEnv(''), { __proto__: null });
assert.deepStrictEqual(util.parseEnv('FOO=bar\nFOO=baz\n'),
{ __proto__: null, FOO: 'baz' });
assert.deepStrictEqual(util.parseEnv('\uFEFFA=1\r\nB=2\r\n'),
{ __proto__: null, A: '1', B: '2' });

// Test for invalid input.
assert.throws(() => {
Expand Down