[Pkg-javascript-commits] [node-shell-quote] 36/137: Return empty list when parsing an empty (or whitespace-only) string
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Aug 25 19:19:37 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 14757177ead209f5ae3c9d4a3020fba9f522725f
Author: Tim Cuthbertson <tim at gfxmonk.net>
Date: Wed Apr 17 16:36:23 2013 +1000
Return empty list when parsing an empty (or whitespace-only) string
---
index.js | 6 ++++--
test/parse.js | 3 +++
test/quote.js | 1 +
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/index.js b/index.js
index 65f663b..e1e97ad 100644
--- a/index.js
+++ b/index.js
@@ -13,9 +13,11 @@ exports.quote = function (xs) {
};
exports.parse = function parse (s, env) {
- if (!env) env = {};
var chunker = /(['"])((\\\1|[^\1])*?)\1|(\\ |\S)+/g;
- return s.match(chunker).map(function (s) {
+ var match = s.match(chunker);
+ if (!match) return [];
+ if (!env) env = {};
+ return match.map(function (s) {
if (/^'/.test(s)) {
return s
.replace(/^'|'$/g, '')
diff --git a/test/parse.js b/test/parse.js
index d52b781..075f1f8 100644
--- a/test/parse.js
+++ b/test/parse.js
@@ -10,6 +10,9 @@ test('parse shell commands', function (t) {
t.same(parse('a b\\ c d'), [ 'a', 'b c', 'd' ]);
t.same(parse('\\$beep bo\\`op'), [ '$beep', 'bo`op' ]);
t.same(parse('echo "foo = \\"foo\\""'), [ 'echo', 'foo = "foo"' ]);
+ t.same(parse(''), []);
+ t.same(parse(' '), []);
+ t.same(parse("\t"), []);
t.end();
});
diff --git a/test/quote.js b/test/quote.js
index d6146e4..b828ad0 100644
--- a/test/quote.js
+++ b/test/quote.js
@@ -11,5 +11,6 @@ test('quote', function (t) {
quote([ '$', '`', '\'' ]),
'\\$ \\` "\'"'
);
+ t.equal(quote([]), '');
t.end();
});
--
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