From 25973248ff901e2a5793a3caa3ffd16a71132fcb Mon Sep 17 00:00:00 2001 From: Vadym Date: Sun, 20 Mar 2022 16:38:44 +0200 Subject: [PATCH 1/4] Fixed regex to process default values correctly --- lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b4e63a..c873cc7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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 } From 85aa43b2702965b2aa8f84cf3e31e8957f5db3a4 Mon Sep 17 00:00:00 2001 From: Vadym Date: Sun, 20 Mar 2022 16:39:06 +0200 Subject: [PATCH 2/4] Added new test cases --- tests/.env | 2 ++ tests/main.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/tests/.env b/tests/.env index 287f40c..26017c1 100644 --- a/tests/.env +++ b/tests/.env @@ -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 @@ -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 diff --git a/tests/main.js b/tests/main.js index f59300a..e3b364d 100644 --- a/tests/main.js +++ b/tests/main.js @@ -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() + }) }) }) From a8bebeb755ccc232e8931d95830bc8104e41a929 Mon Sep 17 00:00:00 2001 From: Vadym Date: Sun, 20 Mar 2022 16:56:00 +0200 Subject: [PATCH 3/4] Fixed npm test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef0ca07..cb98673 100644 --- a/package.json +++ b/package.json @@ -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", From c43787d1cc54ced526ff419dcb18d774419c808e Mon Sep 17 00:00:00 2001 From: Vadym Date: Sun, 20 Mar 2022 16:57:22 +0200 Subject: [PATCH 4/4] Bump v8.0.3 --- package-lock.json | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42df4a5..f4e1446 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,12 @@ { "name": "dotenv-expand", - "version": "8.0.2", + "version": "8.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "8.0.2", + "name": "dotenv-expand", + "version": "8.0.3", "license": "BSD-2-Clause", "devDependencies": { "@types/node": "^17.0.8", diff --git a/package.json b/package.json index cb98673..4edef19 100644 --- a/package.json +++ b/package.json @@ -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",