chjj/marked — pull request #459 by suprememoocow (2014-07-29 21:04:51+00:00)
Title: Deal with catastrophic backtracking in the `em` regexp

This PR works-around a situation in the v8 regex parser in which, given a sufficiently long string, causes the regular expression engine in node.js/chrome to melt down. This is due to v8's backtracking regular expression implementation.

In Firefox and Safari OSX, a 2k long string take 95ms and 41ms respectively to execute. In Chrome, the same string takes 298024ms. During this time, the browser/node.js will effectively be locked up, blocking the event loop.

While the example may seem a bit odd, it's derived from customer data which caused our application to lockup.

```
marked.InlineLexer.output("

-;sqlite3pp::query::query_iterator::query_iterator(sqlite3pp::query*);;\n"+
"-;sqlite3pp::query::begin();;\n"+
"-;trigger::SyncSession::replayRemoteInsertionsInTable(std::__1::basic_string, std::__1::allocator >&);;\n"+
"-;trigger::SyncSession::replayRemoteInsertions();;\n"+
"-;boost::function0::operator()() const;;\n"+
"-;trigger::SyncSession::processAllTables()::$_12::operator()(boost::function const&) const;;\n"+
"-;trigger::SyncSession::processAllTables();;\n"+
"-;trigger::SyncSession::sync(std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, boost::function, boost::function, boost::function, boost::function, boost::function, boost::function, boost::function, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > > const&, void const*)>, bool, void const*, bool);;\n"+
"XCxxSyncSession;Y:;XY.mm;253\n"+
"XCxxSyncSession;Y:;XY.mm;240\n"+
"XYZ;YLocalDatabaseAtPath:withRemoteDatabaseAtPath:error:;XYZ.mm;909\n"+
"XYZ;YLocalDatabaseAtPath:withRemoteDatabaseAtPath:error:;XYZ.mm;894\n"+
"XDatabaseMerging;performYWithDatabase:completion:;XDatabaseMerging.m;146\n"+
"XDatabaseMerging;performYWithDatabase:completion:;XDatabaseMerging.m;125\n"+
"XDatabaseMerging;performYWithDatabases:completion:;XDatabaseMerging.m;109\n"+
"XRemoteLibraryManager;sync;XRemoteLibraryManager.mm;2212

\n"+
"\n"+
"\n", {}, {
gfm: true,
linkify: true,
});
```