cmark

My personal build of CMark ✏️

Commit
58dd044ca1ea8316f4f4b6034eec12d204cc6913
Parent
d4711bb865a17dcefb3b0907c0d452ef49c33c16
Author
John MacFarlane <jgm@berkeley.edu>
Date

Don't allow link destinations with unbalanced unescaped parentheses.

See commonmark/commonmark.js#177.

Diffstat

1 file changed, 4 insertions, 3 deletions

Status File Name N° Changes Insertions Deletions
Modified src/inlines.c 7 4 3
diff --git a/src/inlines.c b/src/inlines.c
@@ -439,8 +439,9 @@ static int scan_delims(subject *subj, unsigned char c, bool *can_open,
     *can_close = right_flanking &&
                  (!left_flanking || cmark_utf8proc_is_punctuation(after_char));
   } else if (c == '\'' || c == '"') {
-    *can_open = left_flanking && !right_flanking &&
-	         before_char != ']' && before_char != ')';
+    *can_open = left_flanking &&
+         (!right_flanking || before_char == '(' || before_char == '[') &&
+         before_char != ']' && before_char != ')';
     *can_close = right_flanking;
   } else {
     *can_open = left_flanking;
@@ -954,7 +955,7 @@ static bufsize_t manual_scan_link_url_2(cmark_chunk *input, bufsize_t offset,
       }
     }
 
-  if (i >= input->len)
+  if (i >= input->len || nb_p != 0)
     return -1;
 
   {