Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90e6199

Browse files
committed
Ensure Object.prototype is not augmented by _.merge.
1 parent67389a8 commit90e6199

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

‎lodash.js‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,20 +1224,6 @@
12241224
return result;
12251225
}
12261226

1227-
/**
1228-
* Gets the value at `key`, unless `key` is "__proto__".
1229-
*
1230-
* @private
1231-
* @param {Object} object The object to query.
1232-
* @param {string} key The key of the property to get.
1233-
* @returns {*} Returns the property value.
1234-
*/
1235-
function safeGet(object, key) {
1236-
return key == '__proto__'
1237-
? undefined
1238-
: object[key];
1239-
}
1240-
12411227
/**
12421228
* Converts `set` to an array of its values.
12431229
*
@@ -6618,6 +6604,29 @@
66186604
return array;
66196605
}
66206606

6607+
/**
6608+
* Gets the value at `key`, unless `key` is "__proto__" or "prototype".
6609+
*
6610+
* @private
6611+
* @param {Object} object The object to query.
6612+
* @param {string} key The key of the property to get.
6613+
* @returns {*} Returns the property value.
6614+
*/
6615+
function safeGet(object, key) {
6616+
if (key == '__proto__') {
6617+
return;
6618+
}
6619+
6620+
var value = object[key];
6621+
6622+
if (key == 'prototype' &&
6623+
value === objectProto) {
6624+
return;
6625+
}
6626+
6627+
return value;
6628+
}
6629+
66216630
/**
66226631
* Sets metadata for `func`.
66236632
*

‎test/test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7554,6 +7554,17 @@
75547554
skipAssert(assert);
75557555
}
75567556
});
7557+
7558+
QUnit.test('should not merge `Object.prototype` properties', function(assert) {
7559+
assert.expect(1);
7560+
7561+
_.merge({}, { 'constructor': { 'prototype': { 'a': 1 } } });
7562+
7563+
var actual = 'a' in objectProto;
7564+
delete objectProto.a;
7565+
7566+
assert.notOk(actual);
7567+
});
75577568
}());
75587569

75597570
/*--------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp