Skip to content

Commit

Permalink
return '' if flag is string and empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Senior authored and James Halliday committed Feb 21, 2014
1 parent cd46bf9 commit fa63ed4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function (args, opts) {
i++;
}
else {
setArg(key, true);
setArg(key, flags.strings[key] ? '' : true);
}
}
else if (/^-[^-]+/.test(arg)) {
Expand Down Expand Up @@ -119,7 +119,7 @@ module.exports = function (args, opts) {
i++;
}
else {
setArg(key, true);
setArg(key, flags.strings[key] ? '' : true);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ test('stringArgs', function (t) {
t.end();
});

test('empty strings', function(t) {
var s = parse([ '-s' ], { string: 's' }).s;
t.equal(s, '');
t.equal(typeof s, 'string');

var str = parse([ '--str' ], { string: 'str' }).str;
t.equal(str, '');
t.equal(typeof str, 'string');

var letters = parse([ '-at' ], {
string: 't'
});

t.equal(letters.a, true);
t.equal(letters.t, '');

t.end();
});


test('slashBreak', function (t) {
t.same(
parse([ '-I/foo/bar/baz' ]),
Expand Down

0 comments on commit fa63ed4

Please sign in to comment.