Skip to content
Open
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: 33 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,38 @@ static void test_feed_empty_chunk(test_batch_runner *runner) {
cmark_node_free(document);
}

static void test_long_code_fence(test_batch_runner *runner) {
// A closing fence must be at least as long as the opening fence, even
// when the opening fence is longer than 255 characters.
char markdown[1024];
char expected[512];
char *p = markdown;
char *q = expected;

memset(p, '`', 256);
p += 256;
strcpy(p, "\n");
p += 1;
memset(p, '`', 255);
p += 255;
strcpy(p, "\n<script>\n");
p += 10;
memset(p, '`', 256);
p += 256;
strcpy(p, "\n");

strcpy(q, "<pre><code>");
q += 11;
memset(q, '`', 255);
q += 255;
strcpy(q, "\n&lt;script&gt;\n</code></pre>\n");

char *html =
cmark_markdown_to_html(markdown, strlen(markdown), CMARK_OPT_DEFAULT);
STR_EQ(runner, html, expected, "255 backticks don't close a 256 fence");
free(html);
}

static void sub_document(test_batch_runner *runner) {
cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
cmark_node *list = cmark_node_new(CMARK_NODE_LIST);
Expand Down Expand Up @@ -1283,6 +1315,7 @@ int main(void) {
test_safe(runner);
test_feed_across_line_ending(runner);
test_feed_empty_chunk(runner);
test_long_code_fence(runner);
sub_document(runner);
source_pos(runner);
source_pos_inlines(runner);
Expand Down
2 changes: 1 addition & 1 deletion src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,
parser->first_nonspace + 1);
(*container)->as.code.fenced = true;
(*container)->as.code.fence_char = peek_at(input, parser->first_nonspace);
(*container)->as.code.fence_length = (matched > 255) ? 255 : matched;
(*container)->as.code.fence_length = matched;
(*container)->as.code.fence_offset =
(int8_t)(parser->first_nonspace - parser->offset);
(*container)->as.code.info = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef struct {

typedef struct {
unsigned char *info;
uint8_t fence_length;
int fence_length;
uint8_t fence_offset;
unsigned char fence_char;
int8_t fenced;
Expand Down
Loading