Skip to content

Commit 24e42bd

Browse files
authored
Fix exception on missing element from html-to-react
Closes GH-507. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent 3d363e9 commit 24e42bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ast-to-react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function getNodeProps(node, key, opts, renderer, parent, index) {
176176
props.allowDangerousHtml = opts.allowDangerousHtml
177177
props.escapeHtml = opts.escapeHtml
178178
props.skipHtml = opts.skipHtml
179-
props.element = mergeNodeChildren(node, parsedChildren)
179+
props.element = node.element ? mergeNodeChildren(node, parsedChildren) : null
180180
break
181181
}
182182
default:

test/react-markdown.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,11 @@ test('should support formatting at the start of a GFM tasklist (GH-494)', () =>
893893
const expected = '<ul><li><input type="checkbox" readonly=""/><em>a</em></li></ul>'
894894
expect(actual).toEqual(expected)
895895
})
896+
897+
test('should not crash on weird `html-to-react` results', () => {
898+
const input = '<ruby><ruby></ruby></ruby>'
899+
const actual = renderHTML(<MarkdownWithHtml allowDangerousHtml children={input} />)
900+
// Note: this is not conforming to how browsers deal with it.
901+
const expected = '<p><ruby></ruby><ruby></ruby></p>'
902+
expect(actual).toEqual(expected)
903+
})

0 commit comments

Comments
 (0)