Skip to content

Commit

Permalink
Fix exception on missing element from html-to-react
Browse files Browse the repository at this point in the history
Closes GH-507.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
cerkiewny committed Nov 19, 2020
1 parent 3d363e9 commit 24e42bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ast-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function getNodeProps(node, key, opts, renderer, parent, index) {
props.allowDangerousHtml = opts.allowDangerousHtml
props.escapeHtml = opts.escapeHtml
props.skipHtml = opts.skipHtml
props.element = mergeNodeChildren(node, parsedChildren)
props.element = node.element ? mergeNodeChildren(node, parsedChildren) : null
break
}
default:
Expand Down
8 changes: 8 additions & 0 deletions test/react-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,11 @@ test('should support formatting at the start of a GFM tasklist (GH-494)', () =>
const expected = '<ul><li><input type="checkbox" readonly=""/><em>a</em></li></ul>'
expect(actual).toEqual(expected)
})

test('should not crash on weird `html-to-react` results', () => {
const input = '<ruby><ruby></ruby></ruby>'
const actual = renderHTML(<MarkdownWithHtml allowDangerousHtml children={input} />)
// Note: this is not conforming to how browsers deal with it.
const expected = '<p><ruby></ruby><ruby></ruby></p>'
expect(actual).toEqual(expected)
})

0 comments on commit 24e42bd

Please sign in to comment.