From 30f8c2211dc172bf3b792ccd75d1f79f26fe83c5 Mon Sep 17 00:00:00 2001 From: Adrian Matejov Date: Tue, 10 Apr 2018 09:07:03 +0200 Subject: [PATCH 1/3] fix: do not remove $ when env variable not found Signed-off-by: Adrian Matejov --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 730186b..ef5b7d1 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,7 @@ function parse (s, env, opts) { function getVar (_, pre, key) { var r = typeof env === 'function' ? env(key) : env[key]; - if (r === undefined) r = ''; + if (r === undefined) r = '$'; if (typeof r === 'object') { return pre + TOKEN + json.stringify(r) + TOKEN; From 729a5a8eaa99ee0d77068335699e4c7f5e7c700f Mon Sep 17 00:00:00 2001 From: Adrian Matejov Date: Tue, 13 Aug 2019 15:08:13 +0200 Subject: [PATCH 2/3] fix: updated parsing non existing var Signed-off-by: Adrian Matejov --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ef5b7d1..2b6a3b7 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,10 @@ function parse (s, env, opts) { function getVar (_, pre, key) { var r = typeof env === 'function' ? env(key) : env[key]; - if (r === undefined) r = '$'; + if (r === undefined && key != '') + r = ''; + else if (r === undefined) + r = '$'; if (typeof r === 'object') { return pre + TOKEN + json.stringify(r) + TOKEN; From 8b70a680e991b3c4337de02785554a72d0ed8caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 13 Aug 2019 15:14:21 +0200 Subject: [PATCH 3/3] add tests --- test/env.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/env.js b/test/env.js index e1ac7cb..b3faeb0 100644 --- a/test/env.js +++ b/test/env.js @@ -10,6 +10,8 @@ test('expand environment variables', function (t) { t.same(parse('qrs"$zzz"wxy', { zzz: 'tuv' }), [ 'qrstuvwxy' ]); t.same(parse("qrs'$zzz'wxy", { zzz: 'tuv' }), [ 'qrs$zzzwxy' ]); t.same(parse("qrs${zzz}wxy"), [ 'qrswxy' ]); + t.same(parse("qrs$wxy $"), [ 'qrs', '$' ]); + t.same(parse('grep "xy$"'), [ 'grep', 'xy$' ]); t.same(parse("ab$x", { x: 'c' }), [ 'abc' ]); t.same(parse("ab\\$x", { x: 'c' }), [ 'ab$x' ]); t.same(parse("ab${x}def", { x: 'c' }), [ 'abcdef' ]);