Prevent null reference access when unsetting styles
Daniel Gasienica committed
Jun 10, 2014 at 13:04 UTC
7c2dec5bd30bf404e3ae6385f9b897df45c84dd6
2 files changed
+6
-1
src/browser/ui/ReactDOMComponent.js
+1
-1
@@ -307,7 +307,7 @@ ReactDOMComponent.Mixin = {
307
// Unset styles on `lastProp` but not on `nextProp`.
308
for (styleName in lastProp) {
309
if (lastProp.hasOwnProperty(styleName) &&
310
- !nextProp.hasOwnProperty(styleName)) {
310
+ (!nextProp || !nextProp.hasOwnProperty(styleName))) {
311
styleUpdates = styleUpdates || {};
312
styleUpdates[styleName] = '';
313
}
src/browser/ui/__tests__/ReactDOMComponent-test.js
+5
@@ -97,6 +97,11 @@ describe('ReactDOMComponent', function() {
97
expect(stubStyle.display).toEqual('block');
98
expect(stubStyle.fontFamily).toEqual('Helvetica');
99
expect(stubStyle.lineHeight).toEqual('0.5');
100
+
101
+ stub.receiveComponent({props: { style: undefined }}, transaction);
102
+ expect(stubStyle.display).toBe('');
103
+ expect(stubStyle.fontFamily).toBe('');
104
+ expect(stubStyle.lineHeight).toBe('');
105
});
106
107
it("should update styles if initially null", function() {