Skip to content

Commit

Permalink
Log debugger just once per windows newline
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed May 5, 2021
1 parent a74c220 commit 11a44c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/main.js
Expand Up @@ -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 */ {
Expand Down
12 changes: 9 additions & 3 deletions tests/test-parse.js
Expand Up @@ -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')

Expand Down Expand Up @@ -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()

0 comments on commit 11a44c4

Please sign in to comment.