diff --git a/lib/nopt.js b/lib/nopt.js index dbb2030..1fb1135 100644 --- a/lib/nopt.js +++ b/lib/nopt.js @@ -351,8 +351,14 @@ function parse (args, data, remain, types, shorthands) { continue } - if (argType === String && la === undefined) - la = "" + if (argType === String) { + if (la === undefined) { + la = "" + } else if (la.match(/^-{1,2}[^-]+/)) { + la = "" + i -- + } + } if (la && la.match(/^-{2,}$/)) { la = undefined diff --git a/test/basic.js b/test/basic.js index ec2ba26..5c18ac0 100644 --- a/test/basic.js +++ b/test/basic.js @@ -15,6 +15,14 @@ test("Empty String results in empty string, not true", function (t) { t.end() }) +// https://github.com/npm/nopt/issues/65 +test("Empty String should not swallow next flag", function (t) { + var parsed = nopt({ empty: String, foo: String }, {}, ["--empty", "--foo"], 0) + t.same(parsed.empty, "") + t.same(parsed.foo, "") + t.end() +}) + // https://github.com/npm/nopt/issues/66 test("Empty String should not be true when type is single item Array", function (t) { var parsed = nopt({ 'foo': [String] }, {}, ["--foo"], 0)