diff --git a/src/blocks.c b/src/blocks.c index 68d514fc6..377cc0e64 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -755,22 +755,24 @@ static void S_find_first_nonspace(cmark_parser *parser, cmark_chunk *input) { char c; int chars_to_tab = TAB_STOP - (parser->column % TAB_STOP); - parser->first_nonspace = parser->offset; - parser->first_nonspace_column = parser->column; - while ((c = peek_at(input, parser->first_nonspace))) { - if (c == ' ') { - parser->first_nonspace += 1; - parser->first_nonspace_column += 1; - chars_to_tab = chars_to_tab - 1; - if (chars_to_tab == 0) { + if (parser->first_nonspace <= parser->offset) { + parser->first_nonspace = parser->offset; + parser->first_nonspace_column = parser->column; + while ((c = peek_at(input, parser->first_nonspace))) { + if (c == ' ') { + parser->first_nonspace += 1; + parser->first_nonspace_column += 1; + chars_to_tab = chars_to_tab - 1; + if (chars_to_tab == 0) { + chars_to_tab = TAB_STOP; + } + } else if (c == '\t') { + parser->first_nonspace += 1; + parser->first_nonspace_column += chars_to_tab; chars_to_tab = TAB_STOP; + } else { + break; } - } else if (c == '\t') { - parser->first_nonspace += 1; - parser->first_nonspace_column += chars_to_tab; - chars_to_tab = TAB_STOP; - } else { - break; } } @@ -1373,6 +1375,9 @@ static void S_process_line(cmark_parser *parser, const unsigned char *buffer, parser->offset = 0; parser->column = 0; + parser->first_nonspace = 0; + parser->first_nonspace_column = 0; + parser->indent = 0; parser->blank = false; parser->partially_consumed_tab = false; diff --git a/test/pathological_tests.py b/test/pathological_tests.py index 9552b3996..ffe3bf9d6 100644 --- a/test/pathological_tests.py +++ b/test/pathological_tests.py @@ -69,21 +69,24 @@ def badhash(ref): "nested block quotes": ((("> " * 50000) + "a"), re.compile("(
\n){50000}")), + "deeply nested lists": + ("".join(map(lambda x: (" " * x + "* a\n"), range(0,1000))), + re.compile("\n(
\n){999}")), "U+0000 in input": ("abc\u0000de\u0000", re.compile("abc\ufffd?de\ufffd?")), "backticks": - ("".join(map(lambda x: ("e" + "`" * x), range(1,10000))), + ("".join(map(lambda x: ("e" + "`" * x), range(1,5000))), re.compile("^- a\n
\n\n){999}
\n(- a
\n[e`]*
\n$")), "unclosed links A": - ("[a](