diff --git a/README.md b/README.md index cbe691e2..4b72ebfe 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,9 @@ The parsing engine currently supports the following rules: - `BASIC=basic` becomes `{BASIC: 'basic'}` - empty lines are skipped -- lines beginning with `#` are treated as comments - 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 - new lines are expanded if in double quotes (`MULTILINE="new\nline"` becomes ``` @@ -133,6 +133,7 @@ The parsing engine currently supports the following rules: line'} ``` - inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`) +- ` #` indicates a comment for the rest of the line unless it's quoted (`HASH='here # there' # a comment` becomes `{HASH: "here # there"}`). lines starting with `#` are entirely skipped. ## FAQ diff --git a/test/.env b/test/.env index 21822358..5cdb4fdb 100644 --- a/test/.env +++ b/test/.env @@ -22,3 +22,7 @@ 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 6f410c40..9ae8d2e5 100644 --- a/test/main.js +++ b/test/main.js @@ -193,5 +193,12 @@ describe('dotenv', function () { parsed.should.have.property('USERNAME', 'therealnerdybeast@example.tld') done() }) + + 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() + }) }) })