Commit 5d7c35973e5d06b46ca21b5b6e292c56dba7ca23

Martin Mitas 2020-02-16T13:46:16

md_analyze_emph: Detect correctly opener chain when resolving the range. Fixes #107.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f99483..be70ce3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -60,6 +60,10 @@ Fixes:
    Fixed an off-by-one error in the maximal length limit of some segments
    of e-mail addresses used in autolinks.
 
+ * [#107](https://github.com/mity/md4c/issues/107):
+   Fix mis-detection of asterisk-encoded emphasis in some corner cases when
+   length of the opener and closer differs, as in `***foo *bar baz***`.
+
 
 ## Version 0.4.2
 
diff --git a/md4c/md4c.c b/md4c/md4c.c
index a71ba36..b0ef739 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -3689,8 +3689,7 @@ md_analyze_emph(MD_CTX* ctx, int mark_index)
             int i, n_opener_chains;
             unsigned flags = mark->flags;
 
-            /* Apply "rule of three". (This is why we break asterisk opener
-             * marks into multiple chains.) */
+            /* Apply the "rule of three". */
             n_opener_chains = 0;
             opener_chains[n_opener_chains++] = &ASTERISK_OPENERS_intraword_mod3_0;
             if((flags & MD_MARK_EMPH_MOD3_MASK) != MD_MARK_EMPH_MOD3_2)
@@ -3726,7 +3725,7 @@ md_analyze_emph(MD_CTX* ctx, int mark_index)
         if(opener != NULL) {
             SZ opener_size = opener->end - opener->beg;
             SZ closer_size = mark->end - mark->beg;
-            MD_MARKCHAIN* opener_chain = md_mark_chain(ctx, mark_index);
+            MD_MARKCHAIN* opener_chain = md_mark_chain(ctx, opener_index);
 
             if(opener_size > closer_size) {
                 opener_index = md_split_emph_mark(ctx, opener_index, closer_size);
diff --git a/test/coverage.txt b/test/coverage.txt
index 0ff1a2f..cffdf63 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -256,6 +256,16 @@ foo
 (Note the `x` here which turns it over the max. allowed length limit.)
 
 
+### [Issue 107](https://github.com/mity/md4c/issues/107)
+
+```````````````````````````````` example
+***foo *bar baz***
+.
+<p>*<strong>foo <em>bar baz</em></strong></p>
+
+````````````````````````````````
+
+
 ## Code coverage
 
 ### `md_is_unicode_whitespace__()`