summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-03-26 12:48:22 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-03-26 12:49:05 -0700
commit359fb5b47365abaebb1b76ae52aeb27efdd39ae7 (patch)
treefa89d485bc308fd4bf812de8da0adf7087b072af /src
parent7cb92c313c31fc808dded8f476f956447e912fe3 (diff)
Handle buffer split across a CRLF line ending (closes #117).
Adds an internal field to the parser struct to keep track of last_buffer_ended_with_cr.
Diffstat (limited to 'src')
-rw-r--r--src/blocks.c11
-rw-r--r--src/parser.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/src/blocks.c b/src/blocks.c
index d10d1ca..f49ad4e 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -90,6 +90,7 @@ cmark_parser *cmark_parser_new(int options) {
parser->last_line_length = 0;
parser->linebuf = buf;
parser->options = options;
+ parser->last_buffer_ended_with_cr = false;
return parser;
}
@@ -506,6 +507,11 @@ 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 NL if last buffer ended with CR ; see #117
+ buffer++;
+ }
+ parser->last_buffer_ended_with_cr = false;
while (buffer < end) {
const unsigned char *eol;
bufsize_t chunk_len;
@@ -546,8 +552,11 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
buffer += chunk_len;
// skip over line ending characters:
- if (buffer < end && *buffer == '\r')
+ if (buffer < end && *buffer == '\r') {
buffer++;
+ if (buffer == end)
+ parser->last_buffer_ended_with_cr = true;
+ }
if (buffer < end && *buffer == '\n')
buffer++;
}
diff --git a/src/parser.h b/src/parser.h
index b3ff39b..ab21d0f 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -27,6 +27,7 @@ struct cmark_parser {
bufsize_t last_line_length;
cmark_strbuf *linebuf;
int options;
+ bool last_buffer_ended_with_cr;
};
#ifdef __cplusplus