Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Element: Avoid rendering invalid dangerouslySetInnerHTML
  • Loading branch information
aduth committed Apr 11, 2018
commit 92853507e152ea4b0e4f379c6e6dd953466e9aeb
3 changes: 2 additions & 1 deletion element/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ export function renderNativeComponent( type, props, context = {} ) {
// as well.
content = renderChildren( [ props.value ], context );
props = omit( props, 'value' );
} else if ( props.dangerouslySetInnerHTML ) {
} else if ( props.dangerouslySetInnerHTML &&
typeof props.dangerouslySetInnerHTML.__html === 'string' ) {
// Dangerous content is left unescaped.
content = props.dangerouslySetInnerHTML.__html;
} else if ( typeof props.children !== 'undefined' ) {
Expand Down
6 changes: 6 additions & 0 deletions element/test/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ describe( 'renderNativeComponent()', () => {
expect( result ).toBe( '<div>&lt;img/></div>' );
} );

it( 'should not render invalid dangerouslySetInnerHTML', () => {
const result = renderNativeComponent( 'div', { dangerouslySetInnerHTML: { __html: undefined } } );

expect( result ).toBe( '<div></div>' );
} );

it( 'should not escape children with dangerouslySetInnerHTML', () => {
const result = renderNativeComponent( 'div', { dangerouslySetInnerHTML: { __html: '<img/>' } } );

Expand Down