Skip to content

Commit 59d29ea

Browse files
committed
[Fix] quote: preserve empty strings
Fixes #18
1 parent 819bd84 commit 59d29ea

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

quote.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
module.exports = function quote(xs) {
44
return xs.map(function (s) {
5+
if (s === '') {
6+
return '\'\'';
7+
}
58
if (s && typeof s === 'object') {
69
return s.op.replace(/(.)/g, '\\$1');
710
}

test/parse.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ test('parse shell commands', function (t) {
3838
t.deepEqual(parse('# abc def ghi'), [{ comment: ' abc def ghi' }], 'start-of-line comment content is unparsed');
3939
t.deepEqual(parse('xyz # abc def ghi'), ['xyz', { comment: ' abc def ghi' }], 'comment content is unparsed');
4040

41+
t.deepEqual(parse('-x "" -y'), ['-x', '', '-y'], 'empty string is preserved');
42+
4143
t.end();
4244
});

test/quote.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ test("chars for windows paths don't break out", function (t) {
4848
t.equal(quote([x]), '\\`\\:\\\\a\\\\b');
4949
t.end();
5050
});
51+
52+
test('empty strings', function (t) {
53+
t.equal(quote(['-x', '', 'y']), '-x \'\' y');
54+
55+
t.end();
56+
});

0 commit comments

Comments
 (0)