Skip to content

Commit 22057ef

Browse files
azichzpao
authored andcommitted
don't try to use Object.prototype methods as transfer strategies in ReactPropTransferer.mergeProps
While looking up a detail of how `transferPropsTo()` works I noticed that we never check `TransferStrategies.hasOwnProperty(thisKey)` when merging props, just `newProps.hasOwnProperty(thisKey)` and a truthy test for `TransferStrategies[thisKey]`. This means that if our `newProps` has keys like `toString`, `valueOf`, or `constructor` etc. set, we will pull these functions off `TransferStrategies` and invoke them when merging props. In most cases this will just result in a failure to merge and some code without side effects being run but in the case of `valueOf` it will actually generate an exception.
1 parent 0278f01 commit 22057ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/core/ReactPropTransferer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var ReactPropTransferer = {
9595

9696
var transferStrategy = TransferStrategies[thisKey];
9797

98-
if (transferStrategy) {
98+
if (transferStrategy && TransferStrategies.hasOwnProperty(thisKey)) {
9999
transferStrategy(props, thisKey, newProps[thisKey]);
100100
} else if (!props.hasOwnProperty(thisKey)) {
101101
props[thisKey] = newProps[thisKey];

0 commit comments

Comments
 (0)