fletcher / MultiMarkdown-5

Reference implementation of MultiMarkdown; replaces MultiMarkdown v4 (deprecated -- see MMD-6 instead)
https://github.com/fletcher/MultiMarkdown-6
Other
294 stars 46 forks source link

MMD hangs when a list item contains only a backslash #30

Closed antons closed 8 years ago

antons commented 8 years ago

One of our customers discovered that MMD parser hangs when a list item (either bulleted or ordered) contains only a backslash:

* \
1. \

We reproduced the issue as far back as 5.0.1, but did not try versions earlier than that.

fletcher commented 8 years ago

I can't reproduce it, either in latest release or development version, or in 5.0.1.

Parsing the file you give me results in the following:

<ul>
<li>
</li>
<li>
</li>
</ul>

Can you be more specific about how to replicate this?

Thanks!

antons commented 8 years ago

@fletcher I forgot to check which extensions we are using. The hang happens only with escaped-line-breaks.

antons commented 8 years ago

I should note that only one line is enough. This alone triggers it:

* \

And this too:

1. \
fletcher commented 8 years ago

That did it. I can reproduce. Now just need to track down the source of the problem. Thanks!

fletcher commented 8 years ago

UPDATE: Spent a lot of time trying to track this down. Interestingly, during my work the problem began to reproduce itself both with and without the escaped line breaks option. I couldn't identify a specific problem with the PEG recipes.

The problem is that when a list item contains only "\", then the parser tries to process the raw block "\n". For whatever reason, that causes the parser to fail to match, and to endlessly cycle through "recipes" looking for a match. I'm not sure why this happens, and certainly welcome any input.

That said, I am able to prevent the error from reaching the user by ensuring that there is something left in the buffer before continuously cycling through the yyparse() function. A description of the problem is added to the source (parser.leg -> process_raw_blocks()).

I will leave this open for now, as I would prefer a real fix rather than just avoiding the problem. At least until MMD 6 exists. ;)