Skip to content

Commit a8d5bd4

Browse files
committed
Fixes #178, quadratic parsing bug.
1 parent b5c4a22 commit a8d5bd4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/inlines.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,16 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
516516
delimiter *old_closer;
517517
bool opener_found;
518518
bool odd_match;
519-
delimiter *openers_bottom[128];
519+
delimiter *openers_bottom[3][128];
520+
int i;
520521

521522
// initialize openers_bottom:
522-
openers_bottom['*'] = stack_bottom;
523-
openers_bottom['_'] = stack_bottom;
524-
openers_bottom['\''] = stack_bottom;
525-
openers_bottom['"'] = stack_bottom;
523+
for (i=0; i < 3; i++) {
524+
openers_bottom[i]['*'] = stack_bottom;
525+
openers_bottom[i]['_'] = stack_bottom;
526+
openers_bottom[i]['\''] = stack_bottom;
527+
openers_bottom[i]['"'] = stack_bottom;
528+
}
526529

527530
// move back to first relevant delim.
528531
while (closer != NULL && closer->previous != stack_bottom) {
@@ -537,7 +540,7 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
537540
opener_found = false;
538541
odd_match = false;
539542
while (opener != NULL && opener != stack_bottom &&
540-
opener != openers_bottom[closer->delim_char]) {
543+
opener != openers_bottom[closer->length % 3][closer->delim_char]) {
541544
if (opener->can_open && opener->delim_char == closer->delim_char) {
542545
// interior closer of size 2 can't match opener of size 1
543546
// or of size 1 can't match 2
@@ -574,13 +577,10 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
574577
}
575578
closer = closer->next;
576579
}
577-
if (!opener_found && !odd_match) {
580+
if (!opener_found) {
578581
// set lower bound for future searches for openers
579-
// (we don't do this with 'odd_match' set because
580-
// a ** that didn't match an earlier * might turn into
581-
// an opener, and the * might be matched by something
582-
// else.
583-
openers_bottom[old_closer->delim_char] = old_closer->previous;
582+
openers_bottom[old_closer->length % 3][old_closer->delim_char] =
583+
old_closer->previous;
584584
if (!old_closer->can_open) {
585585
// we can remove a closer that can't be an
586586
// opener, once we've seen there's no

0 commit comments

Comments
 (0)