Skip to content

Commit

Permalink
fix: do not remove $ when env variable not found (#32)
Browse files Browse the repository at this point in the history
fix: do not remove $ when env variable not found
  • Loading branch information
goto-bus-stop authored Aug 13, 2019
2 parents 09ed4df + 8b70a68 commit 8f6a1cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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;
Expand Down
2 changes: 2 additions & 0 deletions test/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]);
Expand Down

0 comments on commit 8f6a1cc

Please sign in to comment.