Skip to content

Commit

Permalink
Merge pull request #9 from andyedwardsdfdl/ignore-env-comments
Browse files Browse the repository at this point in the history
Update regex for parseSync so we always ignore lines starting with #
  • Loading branch information
balupton committed Jan 25, 2018
2 parents d579b72 + 66ca2a2 commit e8bf0ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions source/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})

0 comments on commit e8bf0ee

Please sign in to comment.