Skip to content

Commit c2f6b45

Browse files
committedJul 28, 2015
add test
more "direct" split
1 parent d189dbd commit c2f6b45

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎lib/argument_parser.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,8 @@ ArgumentParser.prototype._parseOptional = function (argString) {
738738

739739
// if the option string before the "=" is present, return the action
740740
if (argString.indexOf('=') >= 0) {
741-
var argStringSplit = argString.split('=');
742-
optionString = argStringSplit[0];
743-
argExplicit = argStringSplit.slice(1).join('=');
741+
optionString = argString.split('=', 1)[0];
742+
argExplicit = argString.slice(optionString.length + 1);
744743

745744
if (!!this._optionStringActions[optionString]) {
746745
action = this._optionStringActions[optionString];

‎test/base.js

+10
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ describe('base', function () {
123123
args = parser.parseArgs(['-1']);
124124
assert.equal(args.bar, -1);
125125
});
126+
127+
it("should parse arguments with '='", function () {
128+
parser = new ArgumentParser({debug: true});
129+
parser.addArgument(['-f', '--foo']);
130+
parser.addArgument([ 'bar' ]);
131+
132+
args = parser.parseArgs('-f="foo=nice=path" "bar=nice=path"'.split(' '));
133+
assert.equal(args.foo, '"foo=nice=path"');
134+
assert.equal(args.bar, '"bar=nice=path"');
135+
});
126136

127137
it("No negative number options; neg number is positional argument", function () {
128138
parser = new ArgumentParser({debug: true});

0 commit comments

Comments
 (0)
Please sign in to comment.