File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -755,6 +755,20 @@ describe('images', () => {
755
755
` )
756
756
} )
757
757
758
+ it ( 'should gracefully handle an empty image reference' , ( ) => {
759
+ render (
760
+ compiler ( theredoc `
761
+ ![][1]
762
+ [2]: /xyz.png
763
+ ` )
764
+ )
765
+
766
+ expect ( root . innerHTML ) . toMatchInlineSnapshot ( `
767
+ <p>
768
+ </p>
769
+ ` )
770
+ } )
771
+
758
772
it ( 'should handle an image reference with alt text' , ( ) => {
759
773
render (
760
774
compiler ( theredoc `
@@ -890,6 +904,23 @@ describe('links', () => {
890
904
` )
891
905
} )
892
906
907
+ it ( 'should gracefully handle an empty link reference' , ( ) => {
908
+ render (
909
+ compiler ( theredoc `
910
+ [][1]
911
+ [2]: foo
912
+ ` )
913
+ )
914
+
915
+ expect ( root . innerHTML ) . toMatchInlineSnapshot ( `
916
+ <p>
917
+ <span>
918
+ [][1]
919
+ </span>
920
+ </p>
921
+ ` )
922
+ } )
923
+
893
924
it ( 'list item should break paragraph' , ( ) => {
894
925
render ( compiler ( 'foo\n- item' ) )
895
926
Original file line number Diff line number Diff line change @@ -1799,14 +1799,14 @@ export function compiler(
1799
1799
}
1800
1800
} ,
1801
1801
react ( node , output , state ) {
1802
- return (
1802
+ return refs [ node . ref ] ? (
1803
1803
< img
1804
1804
key = { state . key }
1805
1805
alt = { node . alt }
1806
1806
src = { sanitizeUrl ( refs [ node . ref ] . target ) ! }
1807
1807
title = { refs [ node . ref ] . title }
1808
1808
/>
1809
- )
1809
+ ) : null
1810
1810
} ,
1811
1811
} as MarkdownToJSX . Rule < { alt ?: string ; ref : string } > ,
1812
1812
You can’t perform that action at this time.
0 commit comments