md_analyze_permissive_autolink: Accept path ending with '/'. Fixes #226.
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
diff --git a/src/md4c.c b/src/md4c.c
index 104e87d..47b392c 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -3888,11 +3888,12 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
const MD_CHAR delim_char;
const MD_CHAR* allowed_nonalnum_chars;
int min_components;
+ const MD_CHAR optional_end_char;
} URL_MAP[] = {
- { _T('\0'), _T('.'), _T(".-_"), 2 }, /* host, mandatory */
- { _T('/'), _T('/'), _T("/.-_"), 0 }, /* path */
- { _T('?'), _T('&'), _T("&.-+_=()"), 1 }, /* query */
- { _T('#'), _T('\0'), _T(".-+_") , 1 } /* fragment */
+ { _T('\0'), _T('.'), _T(".-_"), 2, _T('\0') }, /* host, mandatory */
+ { _T('/'), _T('/'), _T("/.-_"), 0, _T('/') }, /* path */
+ { _T('?'), _T('&'), _T("&.-+_=()"), 1, _T('\0') }, /* query */
+ { _T('#'), _T('\0'), _T(".-+_") , 1, _T('\0') } /* fragment */
};
MD_MARK* opener = &ctx->marks[mark_index];
@@ -3933,7 +3934,9 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
int n_open_brackets = 0;
if(URL_MAP[i].start_char != _T('\0')) {
- if(end + 1 >= line_end || CH(end) != URL_MAP[i].start_char || !ISALNUM(end+1))
+ if(end >= line_end || CH(end) != URL_MAP[i].start_char)
+ continue;
+ if(URL_MAP[i].min_components > 0 && (end+1 >= line_end || !ISALNUM(end+1)))
continue;
end++;
}
@@ -3967,6 +3970,10 @@ md_analyze_permissive_autolink(MD_CTX* ctx, int mark_index)
}
}
+ if(end < line_end && URL_MAP[i].optional_end_char != _T('\0') &&
+ CH(end) == URL_MAP[i].optional_end_char)
+ end++;
+
if(n_components < URL_MAP[i].min_components || n_open_brackets != 0)
return;
diff --git a/test/regressions.txt b/test/regressions.txt
index d259476..b251443 100644
--- a/test/regressions.txt
+++ b/test/regressions.txt
@@ -713,3 +713,15 @@ foo
.
<p><code>foo</code></p>
````````````````````````````````
+
+## [Issue 226](https://github.com/mity/md4c/issues/226)
+
+```````````````````````````````` example
+https://example.com/
+https://example.com/dir/
+.
+<p><a href="https://example.com/">https://example.com/</a>
+<a href="https://example.com/dir/">https://example.com/dir/</a></p>
+.
+--fpermissive-url-autolinks
+````````````````````````````````