Skip to content

Commit

Permalink
Fix parsing booleans
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
vojtajina committed Sep 29, 2012
1 parent f28c0e6 commit ee692b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function Argv (args, cwd) {
setArg(key, next);
i++;
}
else if (/true|false/.test(next)) {
else if (/^(true|false)$/.test(next)) {
setArg(key, next === 'true');
i++;
}
Expand Down
13 changes: 13 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,16 @@ test('boolean and alias using explicit true', function (t) {
t.end();
});

// regression, see https://github.com/substack/node-optimist/issues/71
test('boolean and --x=true', function(t) {
var parsed = optimist(['--boool', '--other=true']).boolean('boool').argv;

t.same(parsed.boool, true);
t.same(parsed.other, 'true');

parsed = optimist(['--boool', '--other=false']).boolean('boool').argv;

t.same(parsed.boool, true);
t.same(parsed.other, 'false');
t.end();
});

0 comments on commit ee692b3

Please sign in to comment.