From 3aa56049d4b52b55a2313e51698090ee81e10036 Mon Sep 17 00:00:00 2001 From: Jordan Milne Date: Fri, 12 Sep 2014 04:42:30 -0300 Subject: Better handle trailing backslashes in ATX-style headers Previously something like '# `\' would hang the parser while it waited for an extra character that wasn't there. --- src/blocks.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/blocks.c b/src/blocks.c index 2ac7032..5b38116 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -420,17 +420,17 @@ extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len) static void chop_trailing_hashtags(chunk *ch) { - int n; + int n, orig_n; chunk_rtrim(ch); - n = ch->len - 1; + orig_n = n = ch->len - 1; // if string ends in #s, remove these: while (n >= 0 && peek_at(ch, n) == '#') n--; // the last # was escaped, so we include it. - if (n >= 0 && peek_at(ch, n) == '\\') + if (n != orig_n && n >= 0 && peek_at(ch, n) == '\\') n++; ch->len = n + 1; -- cgit v1.2.3