Skip to content

Commit

Permalink
Merge pull request #614 from motdotla/empty-single-quotes
Browse files Browse the repository at this point in the history
Patch empty values when single or double quoted
  • Loading branch information
motdotla committed Feb 2, 2022
2 parents 4b7a130 + 298e989 commit d6184e5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. See [standa

## [Unreleased](https://github.com/motdotla/dotenv/compare/v15.0.0...master)

## [15.0.1](https://github.com/motdotla/dotenv/compare/v15.0.0...v15.0.1) (2022-02-02)

### Changed

- Properly parse empty single or double quoted values 🐞 ([#614](https://github.com/motdotla/dotenv/pull/614))

## [15.0.0](https://github.com/motdotla/dotenv/compare/v14.3.2...v15.0.0) (2022-01-31)

`v15.0.0` is a major new release with some important breaking changes.
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dotenv",
"version": "15.0.0",
"version": "15.0.1",
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"types": "lib/main.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions tests/.env
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
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 d6184e5

Please sign in to comment.