Skip to content

Commit

Permalink
md_analyze_permissive_autolink: Accept path ending with '/'.
Browse files Browse the repository at this point in the history
Fixes #226.
  • Loading branch information
mity committed Jan 19, 2024
1 parent bbb43fe commit 70b247c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions test/regressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
````````````````````````````````

0 comments on commit 70b247c

Please sign in to comment.