@@ -751,11 +751,11 @@ static int link_label(subject *subj, cmark_chunk *raw_label) {
751751
752752// Return a link, an image, or a literal close bracket.
753753static cmark_node * handle_close_bracket (subject * subj ) {
754- bufsize_t initial_pos , save_pos ;
754+ bufsize_t initial_pos ;
755755 bufsize_t starturl , endurl , starttitle , endtitle , endall ;
756756 bufsize_t n ;
757757 bufsize_t sps ;
758- cmark_reference * ref = NULL ;
758+ cmark_reference * ref ;
759759 bool is_image = false;
760760 cmark_chunk url_chunk , title_chunk ;
761761 cmark_chunk url , title ;
@@ -830,29 +830,24 @@ static cmark_node *handle_close_bracket(subject *subj) {
830830 // skip spaces
831831 raw_label = cmark_chunk_literal ("" );
832832 found_label = link_label (subj , & raw_label );
833+ if (!found_label || raw_label .len == 0 ) {
834+ cmark_chunk_free (subj -> mem , & raw_label );
835+ raw_label = cmark_chunk_dup (& subj -> input , opener -> position ,
836+ initial_pos - opener -> position - 1 );
837+ }
833838
834839 if (!found_label ) {
835840 // If we have a shortcut reference link, back up
836841 // to before the spacse we skipped.
837842 subj -> pos = initial_pos ;
838843 }
839844
840- if (!found_label || raw_label .len == 0 ) {
841- save_pos = subj -> pos ;
842- subj -> pos = opener -> position - 1 ;
843- cmark_chunk_free (subj -> mem , & raw_label );
844- found_label = link_label (subj , & raw_label );
845- subj -> pos = save_pos ;
846- }
847-
848- if (found_label ) {
849- ref = cmark_reference_lookup (subj -> refmap , & raw_label );
850- }
845+ ref = cmark_reference_lookup (subj -> refmap , & raw_label );
846+ cmark_chunk_free (subj -> mem , & raw_label );
851847
852- if (ref ) {
848+ if (ref != NULL ) { // found
853849 url = chunk_clone (subj -> mem , & ref -> url );
854850 title = chunk_clone (subj -> mem , & ref -> title );
855- cmark_chunk_free (subj -> mem , & raw_label );
856851 goto match ;
857852 } else {
858853 goto noMatch ;
0 commit comments