Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;

Expand Down
19 changes: 11 additions & 8 deletions test/pathological_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,24 @@ def badhash(ref):
"nested block quotes":
((("> " * 50000) + "a"),
re.compile("(<blockquote>\n){50000}")),
"deeply nested lists":
("".join(map(lambda x: (" " * x + "* a\n"), range(0,1000))),
re.compile("<ul>\n(<li>a\n<ul>\n){999}<li>a</li>\n</ul>\n(</li>\n</ul>\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("^<p>[e`]*</p>\n$")),
"unclosed links A":
("[a](<b" * 50000,
re.compile("(\[a\]\(&lt;b){50000}")),
("[a](<b" * 30000,
re.compile("(\[a\]\(&lt;b){30000}")),
"unclosed links B":
("[a](b" * 50000,
re.compile("(\[a\]\(b){50000}")),
"many references":
("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,50000 * 16))) + "[0] " * 50000,
re.compile("(\[0\] ){49999}")),
("[a](b" * 30000,
re.compile("(\[a\]\(b){30000}")),
# "many references":
# ("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,5000 * 16))) + "[0] " * 5000,
# re.compile("(\[0\] ){4999}")),
"reference collisions": hash_collisions()
}

Expand Down