Skip to content

Commit

Permalink
Revert to old whitespace-trimming behaviour.
Browse files Browse the repository at this point in the history
Old behaviour is that whitespace gets trimmed, whether quoted or
unquoted.
  • Loading branch information
sneakertack committed Dec 1, 2016
1 parent c830089 commit fcb175b
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
1 change: 1 addition & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]"

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
7 changes: 0 additions & 7 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]')
done()
Expand All @@ -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()
})
})
Expand Down

0 comments on commit fcb175b

Please sign in to comment.