Skip to content

Commit 57bee4e

Browse files
don't let blocks get end lines before their start lines
rdar://72043555
1 parent 1429a7f commit 57bee4e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

api_test/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,14 @@ static void source_pos(test_batch_runner *runner) {
10041004
"> Sure.\n"
10051005
">\n"
10061006
"> 2. Yes, okay.\n"
1007-
"> ![ok](hi \"yes\")\n";
1007+
"> ![ok](hi \"yes\")\n"
1008+
"<!-- HTML Comment -->";
10081009

10091010
cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
10101011
char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
10111012
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
10121013
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
1013-
"<document sourcepos=\"1:1-10:20\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
1014+
"<document sourcepos=\"1:1-11:21\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
10141015
" <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
10151016
" <text sourcepos=\"1:3-1:5\" xml:space=\"preserve\">Hi </text>\n"
10161017
" <emph sourcepos=\"1:6-1:12\">\n"
@@ -1052,6 +1053,8 @@ static void source_pos(test_batch_runner *runner) {
10521053
" </item>\n"
10531054
" </list>\n"
10541055
" </block_quote>\n"
1056+
" <html_block sourcepos=\"11:1-11:21\" xml:space=\"preserve\">&lt;!-- HTML Comment --&gt;\n"
1057+
"</html_block>\n"
10551058
"</document>\n",
10561059
"sourcepos are as expected");
10571060
free(xml);

src/blocks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ static cmark_node *finalize(cmark_parser *parser, cmark_node *b) {
289289
b->end_column = parser->last_line_length;
290290
} else if (S_type(b) == CMARK_NODE_DOCUMENT ||
291291
(S_type(b) == CMARK_NODE_CODE_BLOCK && b->as.code.fenced) ||
292-
(S_type(b) == CMARK_NODE_HEADING && b->as.heading.setext)) {
292+
(S_type(b) == CMARK_NODE_HEADING && b->as.heading.setext) ||
293+
(parser->line_number - 1 < b->end_line)) {
293294
b->end_line = parser->line_number;
294295
b->end_column = parser->curline.size;
295296
if (b->end_column && parser->curline.ptr[b->end_column - 1] == '\n')

0 commit comments

Comments
 (0)