diff --git a/lib/node-gyp.js b/lib/node-gyp.js index d6d6509a7a..b84f17d7e2 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -164,7 +164,9 @@ proto.parseArgv = function parseOpts (argv) { } else { // add the user-defined options to the config name = name.substring(npm_config_prefix.length) - this.opts[name] = val + // gyp@741b7f1 enters an infinite loop when it encounters + // zero-length options so ensure those don't get through. + if (name) this.opts[name] = val } }, this) diff --git a/test/test-options.js b/test/test-options.js new file mode 100644 index 0000000000..5ce314f541 --- /dev/null +++ b/test/test-options.js @@ -0,0 +1,20 @@ +'use strict'; + +var test = require('tape') +var gyp = require('../lib/node-gyp') + +test('options in environment', function (t) { + t.plan(1) + + // Zero-length keys should get filtered out. + process.env.npm_config_ = '42' + // Other keys should get added. + process.env.npm_config_x = '42' + // Except loglevel. + process.env.npm_config_loglevel = 'debug' + + var g = gyp(); + g.parseArgv(['rebuild']) // Also sets opts.argv. + + t.deepEqual(Object.keys(g.opts).sort(), ['argv', 'x']) +})