Skip to content

Commit 10bd4cd

Browse files
committed
v0.2.1
This is an attempt to recreate the git history for v0.2.1.
1 parent f904dcc commit 10bd4cd

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,21 @@ function hasKey (obj, keys) {
175175

176176
function setKey (obj, keys, value) {
177177
var o = obj;
178-
keys.slice(0,-1).forEach(function (key) {
178+
for (var i = 0; i < keys.length-1; i++) {
179+
var key = keys[i];
180+
if (key === '__proto__') return;
179181
if (o[key] === undefined) o[key] = {};
182+
if (o[key] === Object.prototype || o[key] === Number.prototype
183+
|| o[key] === String.prototype) o[key] = {};
184+
if (o[key] === Array.prototype) o[key] = [];
180185
o = o[key];
181-
});
182-
186+
}
187+
183188
var key = keys[keys.length - 1];
189+
if (key === '__proto__') return;
190+
if (o === Object.prototype || o === Number.prototype
191+
|| o === String.prototype) o = {};
192+
if (o === Array.prototype) o = [];
184193
if (o[key] === undefined || typeof o[key] === 'boolean') {
185194
o[key] = value;
186195
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minimist",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "parse argument options",
55
"main": "index.js",
66
"devDependencies": {

test/proto.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var parse = require('../');
2+
var test = require('tape');
3+
4+
test('proto pollution', function (t) {
5+
var argv = parse(['--__proto__.x','123']);
6+
t.equal({}.x, undefined);
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);
36+
t.end();
37+
});
38+
39+
test('proto pollution (constructor)', function (t) {
40+
var argv = parse(['--constructor.prototype.y','123']);
41+
t.equal({}.y, undefined);
42+
t.equal(argv.y, undefined);
43+
t.end();
44+
});

0 commit comments

Comments
 (0)