diff --git a/README.md b/README.md index 4b72ebfe..e0358122 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ The parsing engine currently supports the following rules: - empty lines are skipped - empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`) - single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`) -- leading/trailing whitespace gets trimmed, unless within quotes +- leading/trailing whitespace gets trimmed - new lines are expanded if in double quotes (`MULTILINE="new\nline"` becomes ``` diff --git a/lib/main.js b/lib/main.js index 069bd71f..9a170042 100644 --- a/lib/main.js +++ b/lib/main.js @@ -67,6 +67,7 @@ module.exports = { // quoted mode. value = value.substring(1, validEndingQuote.index + 1) // +1 to counter effects of prior 1st-char slice. if (validEndingQuote[1] === '"') value = value.replace(/\\n/gm, '\n') // For double-quoteds, expand newlines. + value = value.trim(); // Do a final trim on the value. } else { // unquoted mode. value = value.replace(/\s+#.*/, '') // remove EOL-comments, if present. diff --git a/test/.env b/test/.env index 5cdb4fdb..ecfee8b7 100644 --- a/test/.env +++ b/test/.env @@ -19,10 +19,7 @@ RETAIN_INNER_QUOTES={"foo": "bar"} RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}' INCLUDE_SPACE=some spaced out string WHITESPACE_TRIM= trim me -QUOTED_WHITESPACE_NOTRIM_1=' dont trim me ' -QUOTED_WHITESPACE_NOTRIM_2=" dont trim me " USERNAME="therealnerdybeast@example.tld" PARSER_QA_1= 'a'b'c'd'e' # a comment PARSER_QA_2=" mismatched\nquotes ' # should\nnot\nprocess -PARSER_QA_3=" # yes\n # yes\n" # no diff --git a/test/main.js b/test/main.js index 9ae8d2e5..532f51e0 100644 --- a/test/main.js +++ b/test/main.js @@ -183,12 +183,6 @@ describe('dotenv', function () { done() }) - it('retains quoted leading/trailing whitespace', function (done) { - parsed.QUOTED_WHITESPACE_NOTRIM_1.should.eql(' dont trim me ') - parsed.QUOTED_WHITESPACE_NOTRIM_2.should.eql(' dont trim me ') - done() - }) - it('parses email addresses completely', function (done) { parsed.should.have.property('USERNAME', 'therealnerdybeast@example.tld') done() @@ -197,7 +191,6 @@ describe('dotenv', function () { it('handles severe combinations of the above', function (done) { parsed.PARSER_QA_1.should.eql("a'b'c'd'e") parsed.PARSER_QA_2.should.eql('" mismatched\\nquotes \'') - parsed.PARSER_QA_3.should.eql(' # yes\n # yes\n') done() }) })