Commit 561f52e05f15dd7f9cdde710d51ae4ac9062cc1d

Martin Mitas 2020-01-05T18:33:46

md_is_autolink_email: Fix an off-by-one error. Fixes #100.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d063d25..a83c44b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,10 @@ Fixes:
    (This does not affect you unless you are on Windows and explicitly define
    the macro when building MD4C.)
 
+ * [#100](https://github.com/mity/md4c/issues/100):
+   Fixed an off-by-one error in the maximal length limit of some segments
+   of e-mail addresses used in autolinks.
+
 
 ## Version 0.4.2
 
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 8737eba..c84c18d 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -2900,7 +2900,7 @@ md_is_autolink_email(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end)
         return FALSE;
     off++;
 
-    /* Labels delimited with '.'; each label is sequence of 1 - 62 alnum
+    /* Labels delimited with '.'; each label is sequence of 1 - 63 alnum
      * characters or '-', but '-' is not allowed as first or last char. */
     label_len = 0;
     while(off < max_end) {
@@ -2913,7 +2913,7 @@ md_is_autolink_email(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end)
         else
             break;
 
-        if(label_len > 62)
+        if(label_len > 63)
             return FALSE;
 
         off++;
diff --git a/test/coverage.txt b/test/coverage.txt
index 7847736..0ff1a2f 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -232,7 +232,6 @@ foo
 
 ### [Issue 97](https://github.com/mity/md4c/issues/97)
 
-
 ```````````````````````````````` example
 *a **b c* d**
 .
@@ -241,6 +240,22 @@ foo
 ````````````````````````````````
 
 
+### [Issue 100](https://github.com/mity/md4c/issues/100)
+
+```````````````````````````````` example
+<foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123>
+.
+<p><a href="mailto:foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123">foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123</a></p>
+````````````````````````````````
+
+```````````````````````````````` example
+<foo@123456789012345678901234567890123456789012345678901234567890123x.123456789012345678901234567890123456789012345678901234567890123>
+.
+<p>&lt;foo@123456789012345678901234567890123456789012345678901234567890123x.123456789012345678901234567890123456789012345678901234567890123&gt;</p>
+````````````````````````````````
+(Note the `x` here which turns it over the max. allowed length limit.)
+
+
 ## Code coverage
 
 ### `md_is_unicode_whitespace__()`