diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index a1be0e38c9..02bc0a8cb8 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1529,8 +1529,10 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMSelect-test.js * should not control when using `defaultValue` * should allow setting `defaultValue` with multiple * should allow setting `value` +* should allow setting `value` to __proto__ * should not throw with `value` and without children * should allow setting `value` with multiple +* should allow setting `value` to __proto__ with multiple * should not select other options automatically * should reset child options selected when they are changed and `value` is set * should allow setting `value` with `objectToString` diff --git a/src/renderers/dom/fiber/wrappers/ReactDOMFiberSelect.js b/src/renderers/dom/fiber/wrappers/ReactDOMFiberSelect.js index 4659ec7f01..7cf83e20ef 100644 --- a/src/renderers/dom/fiber/wrappers/ReactDOMFiberSelect.js +++ b/src/renderers/dom/fiber/wrappers/ReactDOMFiberSelect.js @@ -89,10 +89,11 @@ function updateOptions( let selectedValues = (propValue: Array); let selectedValue = {}; for (let i = 0; i < selectedValues.length; i++) { - selectedValue['' + selectedValues[i]] = true; + // Prefix to avoid chaos with special keys. + selectedValue['$' + selectedValues[i]] = true; } for (let i = 0; i < options.length; i++) { - var selected = selectedValue.hasOwnProperty(options[i].value); + var selected = selectedValue.hasOwnProperty('$' + options[i].value); if (options[i].selected !== selected) { options[i].selected = selected; } diff --git a/src/renderers/dom/shared/wrappers/__tests__/ReactDOMSelect-test.js b/src/renderers/dom/shared/wrappers/__tests__/ReactDOMSelect-test.js index e9f29951a8..efd29196dd 100644 --- a/src/renderers/dom/shared/wrappers/__tests__/ReactDOMSelect-test.js +++ b/src/renderers/dom/shared/wrappers/__tests__/ReactDOMSelect-test.js @@ -128,6 +128,29 @@ describe('ReactDOMSelect', () => { expect(node.value).toEqual('gorilla'); }); + it('should allow setting `value` to __proto__', () => { + var stub = ( + + ); + var options = stub.props.children; + var container = document.createElement('div'); + stub = ReactDOM.render(stub, container); + var node = ReactDOM.findDOMNode(stub); + + expect(node.value).toBe('__proto__'); + + // Changing the `value` prop should change the selected option. + ReactDOM.render( + , + container, + ); + expect(node.value).toEqual('gorilla'); + }); + it('should not throw with `value` and without children', () => { var stub = + + + + + ); + var options = stub.props.children; + var container = document.createElement('div'); + stub = ReactDOM.render(stub, container); + var node = ReactDOM.findDOMNode(stub); + + expect(node.options[0].selected).toBe(false); // monkey + expect(node.options[1].selected).toBe(true); // __proto__ + expect(node.options[2].selected).toBe(true); // gorilla + + // Changing the `value` prop should change the selected options. + ReactDOM.render( + , + container, + ); + + expect(node.options[0].selected).toBe(true); // monkey + expect(node.options[1].selected).toBe(false); // __proto__ + expect(node.options[2].selected).toBe(false); // gorilla + }); + it('should not select other options automatically', () => { var stub = (