diff --git a/lib/main.js b/lib/main.js index e6c591c6..054114aa 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,7 +31,7 @@ function log (message /*: string */) { const NEWLINE = '\n' const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/ const RE_NEWLINES = /\\n/g -const NEWLINES_MATCH = /\n|\r|\r\n/ +const NEWLINES_MATCH = /\r\n|\n|\r/ // Parses src into an Object function parse (src /*: string | Buffer */, options /*: ?DotenvParseOptions */) /*: DotenvParseOutput */ { diff --git a/tests/test-parse.js b/tests/test-parse.js index 5a859dfa..d042fc97 100644 --- a/tests/test-parse.js +++ b/tests/test-parse.js @@ -9,7 +9,7 @@ const dotenv = require('../lib/main') const parsed = dotenv.parse(fs.readFileSync('tests/.env', { encoding: 'utf8' })) -t.plan(27) +t.plan(28) t.type(parsed, Object, 'should return an object') @@ -70,7 +70,13 @@ const RNPayload = dotenv.parse(Buffer.from('SERVER=localhost\r\nPASSWORD=passwor t.same(RNPayload, expectedPayload, 'can parse (\\r\\n) line endings') // test debug path -const logStub = sinon.stub(console, 'log') +let logStub = sinon.stub(console, 'log') dotenv.parse(Buffer.from('what is this'), { debug: true }) -t.ok(logStub.called) +t.ok(logStub.calledOnce) +logStub.restore() + +// test that debug in windows (\r\n lines) logs just once per line +logStub = sinon.stub(console, 'log') +dotenv.parse(Buffer.from('HEY=there\r\n'), { debug: true }) +t.ok(logStub.calledOnce) logStub.restore()