-
-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Copied from original repo. Single comment from @sampsyo with no upvotes:
https://web.archive.org/web/20200904203601/https://github.com/substack/minimist/issues/75/
Consider this tiny program that uses a single boolean flag:
var minimist = require('minimist');
console.log(minimist(process.argv.slice(2), {
boolean: ['f']
}));
It works as expected for most arguments:
$ node foo.js -f xxx
{ _: [ 'xxx' ], f: true }
But, shockingly, if the argument happens to contain the strings "true" or "false" anywhere in the string, then the argument gets reinterpreted as an argument for the -f flag:
$ node foo.js -f xxxtruexxx
{ _: [], f: false }
$ node foo.js -f xxxfalsexxx
{ _: [], f: false }
The value of the -f
flag is false in both cases, but the argument mysteriously vanishes from the _
array.
This is especially surprising if, for example, your program works fine until you happen to use a file with "true" in its name. I would expect the argument list to be left alone entirely, regardless of its content, when used with a boolean flag.
Tests run with [email protected]
using Node v4.2.1 on OS X.