Skip to content

Commit

Permalink
use .test() instead of .match() to not crash on non-string values in …
Browse files Browse the repository at this point in the history
…the arguments array
  • Loading branch information
James Halliday committed Feb 9, 2014
1 parent ec2dc82 commit 7e0d1ad
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -49,18 +49,18 @@ module.exports = function (args, opts) {
for (var i = 0; i < args.length; i++) {
var arg = args[i];

if (arg.match(/^--.+=/)) {
if (/^--.+=/.test(arg)) {
// Using [\s\S] instead of . because js doesn't support the
// 'dotall' regex modifier. See:
// http://stackoverflow.com/a/1068308/13216
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
setArg(m[1], m[2]);
}
else if (arg.match(/^--no-.+/)) {
else if (/^--no-.+/.test(arg)) {
var key = arg.match(/^--no-(.+)/)[1];
setArg(key, false);
}
else if (arg.match(/^--.+/)) {
else if (/^--.+/.test(arg)) {
var key = arg.match(/^--(.+)/)[1];
var next = args[i + 1];
if (next !== undefined && !next.match(/^-/)
Expand All @@ -77,7 +77,7 @@ module.exports = function (args, opts) {
setArg(key, true);
}
}
else if (arg.match(/^-[^-]+/)) {
else if (/^-[^-]+/.test(arg)) {
var letters = arg.slice(1,-1).split('');

var broken = false;
Expand Down

0 comments on commit 7e0d1ad

Please sign in to comment.