Commit e97d0250bbf865b9d342401b7630d977e761c18f

Martin Mitas 2019-11-03T13:44:29

Link label comparision fixes. * md_link_label_cmp: To match the labels, the loop has to reach ends of the labels for both of them. * md_link_label_cmp_load_fold_info: Collapse consequtive whitespace into a single ' ' for the label comparison purposes. Fixes #96.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93258cf..4c11aa1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,9 @@ Fixes:
  * [#95](https://github.com/mity/md4c/issues/95):
    `md_is_container_mark()`: Ordered list mark requires at least one digit.
 
+ * [#96](https://github.com/mity/md4c/issues/96):
+   Some fixes for link label comparison.
+
 
 ## Version 0.3.4
 
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 3745cf3..2b4bfd5 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -1530,7 +1530,7 @@ md_link_label_cmp_load_fold_info(const CHAR* label, OFF off, SZ size,
     SZ char_size;
 
     if(off >= size) {
-        /* Treat end of link label as a whitespace. */
+        /* Treat end of a link label as a whitespace. */
         goto whitespace;
     }
 
@@ -1554,7 +1554,7 @@ md_link_label_cmp_load_fold_info(const CHAR* label, OFF off, SZ size,
 whitespace:
     fold_info->codepoints[0] = _T(' ');
     fold_info->n_codepoints = 1;
-    return off;
+    return md_skip_unicode_whitespace(label, off, size);
 }
 
 static int
@@ -1572,7 +1572,7 @@ md_link_label_cmp(const CHAR* a_label, SZ a_size, const CHAR* b_label, SZ b_size
 
     a_off = md_skip_unicode_whitespace(a_label, 0, a_size);
     b_off = md_skip_unicode_whitespace(b_label, 0, b_size);
-    while(!a_reached_end  &&  !b_reached_end) {
+    while(!a_reached_end  ||  !b_reached_end) {
         /* If needed, load fold info for next char. */
         if(a_fi_off >= a_fi.n_codepoints) {
             a_fi_off = 0;
diff --git a/test/coverage.txt b/test/coverage.txt
index 7ff297f..24a99da 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -213,6 +213,23 @@ foo
 ````````````````````````````````
 
 
+### [Issue 96](https://github.com/mity/md4c/issues/96)
+
+```````````````````````````````` example
+[ab]: /foo
+[a] [ab] [abc]
+.
+<p>[a] <a href="/foo">ab</a> [abc]</p>
+````````````````````````````````
+
+```````````````````````````````` example
+[a b]: /foo
+[a   b]
+.
+<p><a href="/foo">a   b</a></p>
+````````````````````````````````
+
+
 ## Code coverage
 
 ### `md_is_unicode_whitespace__()`