diff options
-rw-r--r-- | src/blocks.c | 8 | ||||
-rw-r--r-- | test/regression.txt | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/blocks.c b/src/blocks.c index df19752..085f89c 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -563,10 +563,16 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer, const unsigned char *end = buffer + len; static const uint8_t repl[] = {239, 191, 189}; - if (parser->last_buffer_ended_with_cr && *buffer == '\n') { + // Skip UTF-8 BOM if present; see #334 + if (parser->line_number == 0 && parser->column == 0 && len >= 3 && + *buffer == 0xEF && *(buffer + 1) == 0xBB && + *(buffer + 2) == 0xBF) { + buffer += 3; + } else if (parser->last_buffer_ended_with_cr && *buffer == '\n') { // skip NL if last buffer ended with CR ; see #117 buffer++; } + parser->last_buffer_ended_with_cr = false; while (buffer < end) { const unsigned char *eol; diff --git a/test/regression.txt b/test/regression.txt index 62b1e7e..d77c8f2 100644 --- a/test/regression.txt +++ b/test/regression.txt @@ -154,3 +154,11 @@ Issue #289. . <p>[a](<b) c></p> ```````````````````````````````` + +Issue #334 - UTF-8 BOM + +```````````````````````````````` example +# Hi +. +<h1>Hi</h1> +```````````````````````````````` |