Skip to content

Commit

Permalink
Backport: Skip UTF-8 BOM at the beginning of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Jan 17, 2012
1 parent 3b67fa5 commit e9588e0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ext/redcarpet/markdown.c
Expand Up @@ -2361,6 +2361,7 @@ 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;
Expand All @@ -2377,6 +2378,12 @@ sd_markdown_render(struct buf *ob, const uint8_t *document, size_t doc_size, str

/* 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;
Expand Down

0 comments on commit e9588e0

Please sign in to comment.