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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
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__()`