Skip to content

Commit

Permalink
Add test for empty single or double quotes value
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Feb 2, 2022
1 parent 4b7a130 commit 86a96a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function parse (src) {
const maybeQuote = value[0]

// Remove surrounding quotes
value = value.replace(/^(['"])([\s\S]+)\1$/mg, '$2')
value = value.replace(/^(['"])([\s\S]*)\1$/mg, '$2')

// Expand newlines if double quoted
if (maybeQuote === '"') {
Expand Down
2 changes: 2 additions & 0 deletions tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ BASIC=basic
# previous line intentionally left blank
AFTER_LINE=after_line
EMPTY=
EMPTY_SINGLE_QUOTES=''
EMPTY_DOUBLE_QUOTES=""
SINGLE_QUOTES='single_quotes'
SINGLE_QUOTES_SPACED=' single quotes '
DOUBLE_QUOTES="double_quotes"
Expand Down
4 changes: 4 additions & 0 deletions tests/test-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ t.equal(parsed.AFTER_LINE, 'after_line', 'reads after a skipped line')

t.equal(parsed.EMPTY, '', 'defaults empty values to empty string')

t.equal(parsed.EMPTY_SINGLE_QUOTES, '', 'defaults empty values to empty string')

t.equal(parsed.EMPTY_DOUBLE_QUOTES, '', 'defaults empty values to empty string')

t.equal(parsed.SINGLE_QUOTES, 'single_quotes', 'escapes single quoted values')

t.equal(parsed.SINGLE_QUOTES_SPACED, ' single quotes ', 'respects surrounding spaces in single quotes')
Expand Down

0 comments on commit 86a96a8

Please sign in to comment.