Skip to content

Commit

Permalink
Merge pull request #71 from devule/bracket-notation-fix
Browse files Browse the repository at this point in the history
Bracket notation fix
  • Loading branch information
motdotla authored Mar 21, 2022
2 parents a646d5c + c43787d commit 7fe3ef5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

function _interpolate (envValue, environment, config) {
const matches = envValue.match(/(.?\${*[\w]*(?::-)?[\w]*}*)/g) || []
const matches = envValue.match(/(.?\${*[\w]*(?::-[\w/]*)?}*)/g) || []

return matches.reduce(function (newEnv, match, index) {
const parts = /(.?)\${*([\w]*(?::-)?[\w]*)?}*/g.exec(match)
const parts = /(.?)\${*([\w]*(?::-[\w/]*)?)?}*/g.exec(match)
if (!parts || parts.length === 0) {
return newEnv
}
Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotenv-expand",
"version": "8.0.2",
"version": "8.0.3",
"description": "Expand environment variables using dotenv",
"main": "lib/main.js",
"types": "lib/main.d.ts",
Expand All @@ -18,7 +18,7 @@
"dts-check": "tsc --project tests/types/tsconfig.json",
"lint": "standard",
"pretest": "npm run lint && npm run dts-check",
"test": "lab tests/* --coverage"
"test": "lab tests --coverage"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ UNDEFINED_EXPAND_WITH_DEFINED_NESTED=${UNDEFINED_ENV_KEY:-${MACHINE:-default}}
UNDEFINED_EXPAND_WITH_DEFAULT=${UNDEFINED_ENV_KEY:-default}
UNDEFINED_EXPAND_WITH_DEFAULT_NESTED=${UNDEFINED_ENV_KEY:-${UNDEFINED_ENV_KEY_2:-default}}
UNDEFINED_EXPAND_WITH_DEFAULT_NESTED_TWICE=${UNDEFINED_ENV_KEY:-${UNDEFINED_ENV_KEY_2${UNDEFINED_ENV_KEY_3:-default}}}
UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS=${UNDEFINED_ENV_KEY:-/default/path}
MONGOLAB_DATABASE=heroku_db
MONGOLAB_USER=username
MONGOLAB_PASSWORD=password
Expand All @@ -24,3 +25,4 @@ MONGOLAB_URI_RECURSIVELY=mongodb://${MONGOLAB_USER_RECURSIVELY}@${MONGOLAB_DOMAI
WITHOUT_CURLY_BRACES_URI=mongodb://$MONGOLAB_USER:$MONGOLAB_PASSWORD@$MONGOLAB_DOMAIN:$MONGOLAB_PORT/$MONGOLAB_DATABASE
WITHOUT_CURLY_BRACES_USER_RECURSIVELY=$MONGOLAB_USER:$MONGOLAB_PASSWORD
WITHOUT_CURLY_BRACES_URI_RECURSIVELY=mongodb://$MONGOLAB_USER_RECURSIVELY@$MONGOLAB_DOMAIN:$MONGOLAB_PORT/$MONGOLAB_DATABASE
WITHOUT_CURLY_BRACES_UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS=$UNDEFINED_ENV_KEY:-/default/path
8 changes: 8 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,13 @@ describe('dotenv-expand', function () {
evaluation.should.eql('undefined')
done()
})

it('should expand with default value correctly', function (done) {
const obj = dotenvExpand.expand(dotenv).parsed

obj.UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS.should.eql('/default/path')
obj.WITHOUT_CURLY_BRACES_UNDEFINED_EXPAND_WITH_DEFAULT_WITH_SPECIAL_CHARACTERS.should.eql('/default/path')
done()
})
})
})

0 comments on commit 7fe3ef5

Please sign in to comment.