cmark

My personal build of CMark ✏️

Commit
8270cf85fc1ee514ccef54d4c545e9ba97b4c003
Parent
32d19737621ac43435ef0c39424b541e867ab642
Author
John MacFarlane <jgm@berkeley.edu>
Date

Fixed `is_autolink`.

Previously *any* link with an absolute URL was treated as an autolink. Closes #50. See also jgm/pandoc#2203.

Diffstat

1 file changed, 8 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 12 8 4
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -239,6 +239,7 @@ is_autolink(cmark_node *node)
 {
 	const char *title;
 	const char *url;
+	cmark_node *link_text;
 
 	if (node->type != CMARK_NODE_LINK) {
 		return false;
@@ -255,10 +256,13 @@ is_autolink(cmark_node *node)
 	if (title != NULL && strlen(title) > 0) {
 		return false;
 	}
-	cmark_consolidate_text_nodes(node);
-	return (strncmp(url,
-	                (char*)node->as.literal.data,
-	                node->as.literal.len) == 0);
+
+	link_text = node->first_child;
+	cmark_consolidate_text_nodes(link_text);
+	return ((int)strlen(url) == link_text->as.literal.len &&
+		strncmp(url,
+	                (char*)link_text->as.literal.data,
+	                link_text->as.literal.len) == 0);
 }
 
 // if node is a block node, returns node.