From 91f0fdd9c13f91d2bd7a691f6b6c55de43634223 Mon Sep 17 00:00:00 2001 From: RaenonX Date: Wed, 30 Jun 2021 04:06:38 -0500 Subject: [PATCH] FIX - Incomplete table should not crash the app (#179) Signed-off-by: RaenonX --- src/components/elements/markdown/main.test.tsx | 10 ++++++++++ .../elements/markdown/transformers/text/main.tsx | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/components/elements/markdown/main.test.tsx b/src/components/elements/markdown/main.test.tsx index e4d986fe..04825c1d 100644 --- a/src/components/elements/markdown/main.test.tsx +++ b/src/components/elements/markdown/main.test.tsx @@ -46,6 +46,16 @@ describe('Markdown', () => { expect(screen.getByText('Y', {selector: 'td'})).toBeInTheDocument(); }); + it('does not crash if the table is incomplete', async () => { + const tableText = 'head | col 2\n:---: | :---:\nX'; + + renderReact(() => {tableText}); + + expect(screen.getByText('head', {selector: 'th'})).toBeInTheDocument(); + expect(screen.getByText('col 2', {selector: 'th'})).toBeInTheDocument(); + expect(screen.getByText('X', {selector: 'td'})).toBeInTheDocument(); + }); + it('renders multiple tables correctly', async () => { const tableText = 'head | col 2\n:---: | :---:\nX | Y'; const table2Text = 'footer | col B\n:---: | :---:\nZ | A'; diff --git a/src/components/elements/markdown/transformers/text/main.tsx b/src/components/elements/markdown/transformers/text/main.tsx index 026a1dfc..1279354c 100644 --- a/src/components/elements/markdown/transformers/text/main.tsx +++ b/src/components/elements/markdown/transformers/text/main.tsx @@ -44,6 +44,10 @@ type TextChildrenProps = { } export const TextChildren = ({children}: TextChildrenProps) => { + if (!children) { + return <>; + } + return ( <> {