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:
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 minimist@1.2.0 using Node v4.2.1 on OS X.
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:
It works as expected for most arguments:
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:
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
minimist@1.2.0
using Node v4.2.1 on OS X.