md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
git clone https://noulin.net/git/md4c.git
Log | Files | Refs | README | LICENSE

commit 25228d5d5c335b38af14d36bcaffb92a684feb25
parent a847f5522e7129f529aa96ec34ba340effb25afe
Author: Martin Mitas <mity@morous.org>
Date:   Sun,  8 Jan 2017 09:25:10 +0100

md_is_link_destination_B: Apply new spec rules for parenthesis.

The specification now allows nesting parenthesis inside a link destination
as long as opening and closing ones are balanced.

Diffstat:
Mmd4c/md4c.c | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -1960,7 +1960,7 @@ md_is_link_destination_B(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end, OFF* p_contents_beg, OFF* p_contents_end) { OFF off = beg; - int in_parentheses = 0; + int parenthesis_level = 0; while(off < max_end) { if(CH(off) == _T('\\') && off+1 < max_end && ISPUNCT(off+1)) { @@ -1971,24 +1971,23 @@ md_is_link_destination_B(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end, if(ISWHITESPACE(off) || ISCNTRL(off)) break; - /* Link destination may include balanced pair of unescaped '(' ')' - * but only if they are not nested. */ + /* Link destination may include balanced pairs of unescaped '(' ')'. + * Note we limit the maximal nesting level by 32 to protect us from + * https://github.com/jgm/cmark/issues/214 */ if(CH(off) == _T('(')) { - if(in_parentheses) + parenthesis_level++; + if(parenthesis_level > 32) return FALSE; - else - in_parentheses = 1; } else if(CH(off) == _T(')')) { - if(in_parentheses) - in_parentheses = 0; - else + if(parenthesis_level == 0) break; + parenthesis_level--; } off++; } - if(in_parentheses || off == beg) + if(parenthesis_level != 0 || off == beg) return FALSE; /* Success. */