From 9ff42cfef5f2414abe715055e54b776a2c3b9a50 Mon Sep 17 00:00:00 2001 From: Evan Jacobs <570070+quantizor@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:45:06 -0400 Subject: [PATCH] fix: gracefully handle missing image references (#554) Closes #524 --- index.compiler.spec.tsx | 31 +++++++++++++++++++++++++++++++ index.tsx | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/index.compiler.spec.tsx b/index.compiler.spec.tsx index 1d41d9a4..b8c6c809 100644 --- a/index.compiler.spec.tsx +++ b/index.compiler.spec.tsx @@ -782,6 +782,20 @@ describe('images', () => { `) }) + it('should gracefully handle an empty image reference', () => { + render( + compiler(theredoc` + ![][1] + [2]: /xyz.png + `) + ) + + expect(root.innerHTML).toMatchInlineSnapshot(` +
+
+ `) + }) + it('should handle an image reference with alt text', () => { render( compiler(theredoc` @@ -917,6 +931,23 @@ describe('links', () => { `) }) + it('should gracefully handle an empty link reference', () => { + render( + compiler(theredoc` + [][1] + [2]: foo + `) + ) + + expect(root.innerHTML).toMatchInlineSnapshot(` ++ + [][1] + +
+ `) + }) + it('list item should break paragraph', () => { render(compiler('foo\n- item')) diff --git a/index.tsx b/index.tsx index a1aba1c8..2425a164 100644 --- a/index.tsx +++ b/index.tsx @@ -1693,14 +1693,14 @@ export function compiler( } }, render(node, output, state) { - return ( + return refs[node.ref] ? (