Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NUL-LF sequence lex #160

Merged
merged 2 commits into from
Oct 11, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,13 @@ static void utf8(test_batch_runner *runner) {
string_with_null, sizeof(string_with_null) - 1, CMARK_OPT_DEFAULT);
STR_EQ(runner, html, "<p>((((" UTF8_REPL "))))</p>\n", "utf8 with U+0000");
free(html);

// Test NUL followed by newline
static const char string_with_nul_lf[] = "```\n\0\n```\n";
html = cmark_markdown_to_html(
string_with_nul_lf, sizeof(string_with_nul_lf) - 1, CMARK_OPT_DEFAULT);
STR_EQ(runner, html, "<pre><code>\xef\xbf\xbd\n</code></pre>\n", "utf8 with \\0\\n");
free(html);
}

static void test_char(test_batch_runner *runner, int valid, const char *utf8,
Expand Down
5 changes: 3 additions & 2 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
cmark_strbuf_put(&parser->linebuf, buffer, chunk_len);
// add replacement character
cmark_strbuf_put(&parser->linebuf, repl, 3);
chunk_len += 1; // so we advance the buffer past NULL
} else {
cmark_strbuf_put(&parser->linebuf, buffer, chunk_len);
}
Expand All @@ -576,7 +575,9 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
if (buffer == end)
parser->last_buffer_ended_with_cr = true;
}
if (buffer < end && *buffer == '\n')
if (buffer < end && *buffer == '\0')
buffer++;
else if (buffer < end && *buffer == '\n')
buffer++;
}
}
Expand Down