From 70b247cf7da02e927a9ba05b52d10fd0109f8d99 Mon Sep 17 00:00:00 2001 From: Martin Mitas Date: Fri, 19 Jan 2024 13:59:45 +0100 Subject: [PATCH] md_analyze_permissive_autolink: Accept path ending with '/'. Fixes #226. --- src/md4c.c | 17 ++++++++++++----- test/regressions.txt | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/md4c.c b/src/md4c.c index 104e87da..47b392c6 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 d259476b..b2514436 100644 --- a/test/regressions.txt +++ b/test/regressions.txt @@ -713,3 +713,15 @@ foo .

foo

```````````````````````````````` + +## [Issue 226](https://github.com/mity/md4c/issues/226) + +```````````````````````````````` example +https://example.com/ +https://example.com/dir/ +. +

https://example.com/ +https://example.com/dir/

+. +--fpermissive-url-autolinks +````````````````````````````````