minimist 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -3
- package/package.json +1 -1
- package/test/proto.js +29 -1
package/index.js
CHANGED
|
@@ -68,13 +68,21 @@ module.exports = function (args, opts) {
|
|
|
68
68
|
|
|
69
69
|
function setKey (obj, keys, value) {
|
|
70
70
|
var o = obj;
|
|
71
|
-
keys.
|
|
71
|
+
for (var i = 0; i < keys.length-1; i++) {
|
|
72
|
+
var key = keys[i];
|
|
73
|
+
if (key === '__proto__') return;
|
|
72
74
|
if (o[key] === undefined) o[key] = {};
|
|
73
|
-
if (o[key] ===
|
|
75
|
+
if (o[key] === Object.prototype || o[key] === Number.prototype
|
|
76
|
+
|| o[key] === String.prototype) o[key] = {};
|
|
77
|
+
if (o[key] === Array.prototype) o[key] = [];
|
|
74
78
|
o = o[key];
|
|
75
|
-
}
|
|
79
|
+
}
|
|
76
80
|
|
|
77
81
|
var key = keys[keys.length - 1];
|
|
82
|
+
if (key === '__proto__') return;
|
|
83
|
+
if (o === Object.prototype || o === Number.prototype
|
|
84
|
+
|| o === String.prototype) o = {};
|
|
85
|
+
if (o === Array.prototype) o = [];
|
|
78
86
|
if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
|
|
79
87
|
o[key] = value;
|
|
80
88
|
}
|
package/package.json
CHANGED
package/test/proto.js
CHANGED
|
@@ -4,6 +4,34 @@ var test = require('tape');
|
|
|
4
4
|
test('proto pollution', function (t) {
|
|
5
5
|
var argv = parse(['--__proto__.x','123']);
|
|
6
6
|
t.equal({}.x, undefined);
|
|
7
|
-
t.equal(argv.__proto__.x,
|
|
7
|
+
t.equal(argv.__proto__.x, undefined);
|
|
8
|
+
t.equal(argv.x, undefined);
|
|
9
|
+
t.end();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('proto pollution (array)', function (t) {
|
|
13
|
+
var argv = parse(['--x','4','--x','5','--x.__proto__.z','789']);
|
|
14
|
+
t.equal({}.z, undefined);
|
|
15
|
+
t.deepEqual(argv.x, [4,5]);
|
|
16
|
+
t.equal(argv.x.z, undefined);
|
|
17
|
+
t.equal(argv.x.__proto__.z, undefined);
|
|
18
|
+
t.end();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('proto pollution (number)', function (t) {
|
|
22
|
+
var argv = parse(['--x','5','--x.__proto__.z','100']);
|
|
23
|
+
t.equal({}.z, undefined);
|
|
24
|
+
t.equal((4).z, undefined);
|
|
25
|
+
t.equal(argv.x, 5);
|
|
26
|
+
t.equal(argv.x.z, undefined);
|
|
27
|
+
t.end();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('proto pollution (string)', function (t) {
|
|
31
|
+
var argv = parse(['--x','abc','--x.__proto__.z','def']);
|
|
32
|
+
t.equal({}.z, undefined);
|
|
33
|
+
t.equal('...'.z, undefined);
|
|
34
|
+
t.equal(argv.x, 'abc');
|
|
35
|
+
t.equal(argv.x.z, undefined);
|
|
8
36
|
t.end();
|
|
9
37
|
});
|