@samitouri / QOS-React / commits / f60a7f722c

Fix SSR crash on a hasOwnProperty attribute (#13303)

Dan Abramov committed Aug 1, 2018 at 20:23 UTC f60a7f722cfd0083ca43387798dde7cd95b2fe26
3 files changed +18 -3
packages/react-dom/src/__tests__/ReactServerRendering-test.js
+13
@@ -174,6 +174,19 @@ describe('ReactDOMServer', () => {
174 (__DEV__ ? '\n in iframe (at **)' : ''),
175 );
176 });
177 +
178 + it('should not crash on poisoned hasOwnProperty', () => {
179 + let html;
180 + expect(
181 + () =>
182 + (html = ReactDOMServer.renderToString(
183 + <div hasOwnProperty="poison">
184 + <span unknown="test" />
185 + </div>,
186 + )),
187 + ).toWarnDev(['React does not recognize the `hasOwnProperty` prop']);
188 + expect(html).toContain('<span unknown="test">');
189 + });
190 });
191
192 describe('renderToStaticMarkup', () => {
packages/react-dom/src/server/ReactPartialRenderer.js
+2 -1
@@ -349,6 +349,7 @@ function processContext(type, context) {
349 return maskedContext;
350 }
351
352 +const hasOwnProperty = Object.prototype.hasOwnProperty;
353 const STYLE = 'style';
354 const RESERVED_PROPS = {
355 children: null,
@@ -368,7 +369,7 @@ function createOpenTagMarkup(
369 let ret = '<' + tagVerbatim;
370
371 for (const propKey in props) {
371 - if (!props.hasOwnProperty(propKey)) {
372 + if (!hasOwnProperty.call(props, propKey)) {
373 continue;
374 }
375 let propValue = props[propKey];
packages/react-dom/src/shared/DOMProperty.js
+3 -2
@@ -66,14 +66,15 @@ export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
66 '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
67 );
68
69 +const hasOwnProperty = Object.prototype.hasOwnProperty;
70 const illegalAttributeNameCache = {};
71 const validatedAttributeNameCache = {};
72
73 export function isAttributeNameSafe(attributeName: string): boolean {
73 - if (validatedAttributeNameCache.hasOwnProperty(attributeName)) {
74 + if (hasOwnProperty.call(validatedAttributeNameCache, attributeName)) {
75 return true;
76 }
76 - if (illegalAttributeNameCache.hasOwnProperty(attributeName)) {
77 + if (hasOwnProperty.call(illegalAttributeNameCache, attributeName)) {
78 return false;
79 }
80 if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {