29

Symptoms

The following input causes stackexchange page to freeze (give it a try :P)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - a

Cause

This is caused by a Catastrophic Backtracking in the horizontal lines regexes. The responsible code should be something like this:

var replacement = "<hr />\n";
text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, replacement);
text = text.replace(/^[ ]{0,2}([ ]?-[ ]?){3,}[ \t]*$/gm, replacement);
text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm, replacement);

Fix

In order to fix this, the regexes can be simplified:

/^( ?-){3,}[ \t]*$/gm

Related post

Regex to parse horizontal rules in Markdown

6

Good thing I tested this out in a separate browser. :)

Used your regex with a small modification to preserve leading spaces that we currently allow in front of horizontal rules. The fix will go out with the next prod build. Thanks!

  • Shameless pug: Ever considered using a newer version of github.com/showdownjs/showdown ? It improved a lot since the fork – Tivie Dec 20 '16 at 9:24
  • Obviously, that should be read as Shameless Pub, not Pug! lol – Tivie Dec 20 '16 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .