[Pkg-javascript-commits] [node-shell-quote] 20/137: one test was wrong, checking for pre escapes
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Aug 25 19:19:35 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-shell-quote.
commit 42b5f8355196d5f2a2c40178576a5d37167e8cb2
Author: James Halliday <mail at substack.net>
Date: Sun Apr 14 20:13:44 2013 -0700
one test was wrong, checking for pre escapes
---
index.js | 13 ++++++-------
test/env.js | 2 +-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/index.js b/index.js
index c22cc6d..a613dc3 100644
--- a/index.js
+++ b/index.js
@@ -23,21 +23,20 @@ exports.parse = function (s, env) {
;
}
else if (/^"/.test(s)) {
- return interpolate(s.replace(/^"|"$/g, ''))
+ return interpolate(s.replace(/^"|"$/g, ''));
}
else return interpolate(s);
})
;
- function getVar (_, x) {
- return String(env[x])
- }
-
function interpolate (s) {
return s
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
- .replace(/\$(\w+)/g, getVar)
- .replace(/\${(\w+)}/g, getVar)
+ .replace(/(^|[^\\])\$(\w+)/g, getVar)
+ .replace(/(^|[^\\])\${(\w+)}/g, getVar)
;
}
+ function getVar (_, pre, key) {
+ return pre + String(env[key]);
+ }
};
diff --git a/test/env.js b/test/env.js
index 20ff7da..b9f9001 100644
--- a/test/env.js
+++ b/test/env.js
@@ -4,7 +4,7 @@ var parse = require('../').parse;
test('expand environment variables', function (t) {
t.same(parse('a $XYZ c', { XYZ: 'b' }), [ 'a', 'b', 'c' ]);
t.same(parse('a${XYZ}c', { XYZ: 'b' }), [ 'abc' ]);
- t.same(parse('a${XYZ}c $XYZ', { XYZ: 'b' }), [ 'abcb b' ]);
+ t.same(parse('a${XYZ}c $XYZ', { XYZ: 'b' }), [ 'abc', 'b' ]);
t.same(parse('"-$X-$Y-"', { X: 'a', Y: 'b' }), [ '-a-b-' ]);
t.same(parse("'-$X-$Y-'", { X: 'a', Y: 'b' }), [ '-$X-$Y-' ]);
t.same(parse('qrs"$zzz"wxy', { zzz: 'tuv' }), [ 'qrstuvwxy' ]);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-shell-quote.git
More information about the Pkg-javascript-commits
mailing list