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(); });