Skip to content

Commit

Permalink
Add more stress tests for the parse function, and update the readme.
Browse files Browse the repository at this point in the history
The tests successfully pass.
  • Loading branch information
sneakertack committed Nov 25, 2016
1 parent 210ad3f commit c830089
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ 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

```
{MULTILINE: 'new
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

Expand Down
4 changes: 4 additions & 0 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ 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: 7 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,12 @@ describe('dotenv', function () {
parsed.should.have.property('USERNAME', '[email protected]')
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()
})
})
})

0 comments on commit c830089

Please sign in to comment.