Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected string parsing with empty arguments #32

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ function parse (args, data, remain, types, shorthands) {
continue
}

if (types[arg] === String && la === undefined)
la = ""

if (la && la.match(/^-{2,}$/)) {
la = undefined
i --
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)",
"main": "lib/nopt.js",
"scripts": {
"test": "node lib/nopt.js"
"test": "node lib/nopt.js && tap test/*"
},
"repository": "http://github.com/isaacs/nopt",
"bin": "./bin/nopt.js",
Expand All @@ -15,5 +15,8 @@
},
"dependencies": {
"abbrev": "1"
},
"devDependencies": {
"tap": "~0.4.8"
}
}
16 changes: 16 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var nopt = require("../")
, test = require('tap').test


test("passing a string results in a string", function (t) {
var parsed = nopt({ key: String }, {}, ["--key", "myvalue"], 0)
t.same(parsed.key, "myvalue")
t.end()
})

// https://github.com/npm/nopt/issues/31
test("Empty String results in empty string, not true", function (t) {
var parsed = nopt({ empty: String }, {}, ["--empty"], 0)
t.same(parsed.empty, "")
t.end()
})