From 66ca2a261b5aa183d0a8274924a2703478628b2b Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Wed, 4 Jan 2017 13:38:24 +0000 Subject: [PATCH] Update regex for parseSync so we always ignore lines starting with # --- source/index.js | 2 +- source/test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/index.js b/source/index.js index 631753b..cbfe9e2 100644 --- a/source/index.js +++ b/source/index.js @@ -63,7 +63,7 @@ module.exports = { const result = {} const lines = src.toString().split('\n') for ( const line of lines ) { - const match = line.match(/^([^=:]+?)[=\:](.*)/) + const match = line.match(/^([^=:#]+?)[=\:](.*)/) if ( match ) { const key = match[1].trim() const value = match[2].trim() diff --git a/source/test.js b/source/test.js index e821c82..25dbea6 100644 --- a/source/test.js +++ b/source/test.js @@ -17,4 +17,16 @@ describe('envfile', function (describe, it) { done() }) }) + + it('comments should be ignored', function (done) { + const envfile2jsonPath = pathUtil.join(__dirname, '..', 'bin', 'envfile2json.js') + const json2envfilePath = pathUtil.join(__dirname, '..', 'bin', 'json2envfile.js') + const command = `echo "#comments with = are ignored\\na=1\\n" | node ${envfile2jsonPath} | node ${json2envfilePath}` + process.env.DEBUG_ESNEXTGUARDIAN = '' + exec(command, function (err, stdout) { + errorEqual(err, null, 'no error to exist') + equal(stdout.trim(), 'a=1', 'stdout to be as expected') + done() + }) + }) })