summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-10-11 14:31:00 +0200
committerGitHub <noreply@github.com>2016-10-11 14:31:00 +0200
commit1f51da22e4d56ae0f0bc3ae75817e99a91038226 (patch)
treeaca99ba07ec025e752b952307cf91e6ebd0a9ab3
parente89187b0604eff3a8251a902bfbbdb3cd7ff415b (diff)
parent920cbd071a85ffabefdb706c257b7c49620fc896 (diff)
Merge pull request #160 from kivikakk/kivikakk/fix-nul-lf-sequence
Fix NUL-LF sequence lex
-rw-r--r--api_test/main.c7
-rw-r--r--src/blocks.c5
2 files changed, 10 insertions, 2 deletions
diff --git a/api_test/main.c b/api_test/main.c
index d493e00..d87e446 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -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,
diff --git a/src/blocks.c b/src/blocks.c
index 3c21fbf..a88c168 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -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);
}
@@ -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++;
}
}