ext/redcarpet/markdown.c in redcarpet-2.0.1 vs ext/redcarpet/markdown.c in redcarpet-2.1.0
- old
+ new
@@ -2359,10 +2359,11 @@
void
sd_markdown_render(struct buf *ob, const uint8_t *document, size_t doc_size, struct sd_markdown *md)
{
#define MARKDOWN_GROW(x) ((x) + ((x) >> 1))
+ static const char UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
struct buf *text;
size_t beg, end;
text = bufnew(64);
@@ -2375,9 +2376,15 @@
/* reset the references table */
memset(&md->refs, 0x0, REF_TABLE_SIZE * sizeof(void *));
/* first pass: looking for references, copying everything else */
beg = 0;
+
+ /* Skip a possible UTF-8 BOM, even though the Unicode standard
+ * discourages having these in UTF-8 documents */
+ if (doc_size >= 3 && memcmp(document, UTF8_BOM, 3) == 0)
+ beg += 3;
+
while (beg < doc_size) /* iterating over lines */
if (is_ref(document, beg, doc_size, &end, md->refs))
beg = end;
else { /* skipping to the next line */
end = beg;