- Commit
- cc50a3aba3e34dc58ca819a65b907871e2ea6fd9
- Parent
- 26182bb868d3da7dd8a3389729bea79d489855b7
- Author
- John MacFarlane <jgm@berkeley.edu>
- Date
Fix "multiple of 3" determination in emph/strong parsing.
We need to store the length of the original delimiter run,
instead of using the length of the remaining delimiters
after some have been subtracted.
Test case:
a***b* c*
Thanks to Raph Levin for reporting.
diff --git a/src/inlines.c b/src/inlines.c
@@ -40,6 +40,7 @@ typedef struct delimiter {
struct delimiter *previous;
struct delimiter *next;
cmark_node *inl_text;
+ bufsize_t length;
unsigned char delim_char;
bool can_open;
bool can_close;
@@ -408,6 +409,7 @@ static void push_delimiter(subject *subj, unsigned char c, bool can_open,
delim->can_open = can_open;
delim->can_close = can_close;
delim->inl_text = inl_text;
+ delim->length = inl_text->as.literal.len;
delim->previous = subj->last_delim;
delim->next = NULL;
if (delim->previous != NULL) {
@@ -553,10 +555,7 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
// interior closer of size 2 can't match opener of size 1
// or of size 1 can't match 2
odd_match = (closer->can_open || opener->can_close) &&
- ((opener->inl_text->as.literal.len +
- closer->inl_text->as.literal.len) %
- 3 ==
- 0);
+ ((opener->length + closer->length) % 3 == 0);
if (opener->delim_char == closer->delim_char && opener->can_open &&
!odd_match) {
opener_found = true;