From da8fb535c9df84f3cd1086f3c8651b5f7ee8989c Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Mon, 19 Dec 2016 12:13:30 +0000 Subject: [PATCH] fix: parser slowness with certain inputs A bad desinged regex was causing the parser to become extremelly slow when given some inputs. Closes #315 --- dist/showdown.js | Bin 72395 -> 72371 bytes dist/showdown.js.map | Bin 213487 -> 213335 bytes dist/showdown.min.js | Bin 29334 -> 29313 bytes dist/showdown.min.js.map | Bin 32594 -> 32594 bytes src/subParsers/blockGamut.js | 6 +++--- src/subParsers/lists.js | 5 +---- .../#312.spaced-dashes-followed-by-char4.html | 3 +++ .../#312.spaced-dashes-followed-by-char4.md | 1 + 8 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 test/issues/#312.spaced-dashes-followed-by-char4.html create mode 100644 test/issues/#312.spaced-dashes-followed-by-char4.md diff --git a/dist/showdown.js b/dist/showdown.js index 61b604df1beb05c45eba8003c3464aa8f6c42ae6..e3eb24dd86406a1d2c24af96ee0bfd1501dd1930 100644 GIT binary patch delta 125 zcmX@Tm1Xl*76EI0Ek%XmjQsMH{PH{nL(7cqu zYNHimN@BHCCige02mnRnkp(xOYRnCp{C_s*O>&#>H9Ch(KJZC>v-`Co9_Hehyv=(bIWcek_q35~^5t^%%}YP0JF{eM7C zgC`r%ERN~MeT<5eFB}k={&y3j>E<1WLrC2yf3_#AFpQ{oGzA&go~~Fv)H||BLA*4{LBtOrFB_J?zZU b%-bconZIyNKm3MCZ8}hrZM(G?^A>FYdlrJ& delta 386 zcmccK#QVOPcf*v=)BW!-a!pTo$tXE}K{zA-^Z-vF7eq{}0P-A!7+EJPcyLX=@R^s< zczU4~qZX0|flfyL$p(D5)Ei=`FJt7JY+%VYdBPmrdJgt7Ds2AnW&6U(0y^B2^?w;{ zzdwz!Ok(ndn6Ty+8+9RsH)rZZ{+4dR@hz{tq5{o;B?FIHA-M@MJJ>4H-j zMYkJlWvmgITrh)edL=ib`E;NeT$2@ASSS0>WSzX>vB7kWQ;eESRX)=N9T-)oPhbOj zdVvO`-1Y^h824P`Q>Zr3F{;&2u#bt+Qm~(%u#m}+2QH?IArcP}k=*`#A(L*z^ab;o oG`3s)VtUELQXCVLw_SssIhuKUBNy{GuIcmF0p;e3GVjs`0E%^ip#T5? diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 30c19ef0cce3b481fe5e732b344cf1a3d04e5a51..020fa7972ccae872ef744a7e60e56f7493f85ea9 100644 GIT binary patch delta 97 zcmbRCl(F$CBfq|uqC#;-etAlMd7gry(!Oce!zj2JD=YGa++XoZ-P pSS^*weWqdpK+$+)!ObsBZB;pfWAYSYwe-^`A9N7jY#$vi4gjz$9iIRI delta 121 zcmZpC$~f&QBfq|uqC#;-etAlMd7gry`9}V9Q(lE?10ADU4F&rcEd~3@Ri=tOa1mXI zfFfKVUcp|o+E}MHS|O$+R!c=cJy$1HQzy}O^2KoB&F@VWRN0GT@?y30(>z;AwuR5A^uXJP&ru0)zmrL zd2(Qp$mX{W8C(lc6QDESRjGa*`w6CC3TKF`xV+rCUfFs4?AHC)m+3 z)W8>HiRtF4sS%8fuAASbEo0&~a0=1!bHzbMhSpbE!oxnnQ5FvhqkSkEgd2(Qp z$mX{W8QDESjvIa*`v{CC3TKv7G!PrCSK1Q772ZG1R~pWQp', options, globals); - text = text.replace(/^ {0,2}( ?\* ?){3,}[ \t]*$/gm, key); - text = text.replace(/^ {0,2}( ?- ?){3,}[ \t]*$/gm, key); - text = text.replace(/^ {0,2}( ?_ ?){3,}[ \t]*$/gm, key); + text = text.replace(/^( ?-){3,}[ \t]*$/gm, key); + text = text.replace(/^( ?\*){3,}[ \t]*$$/gm, key); + text = text.replace(/^( ?_){3,}[ \t]*$$/gm, key); text = showdown.subParser('lists')(text, options, globals); text = showdown.subParser('codeBlocks')(text, options, globals); diff --git a/src/subParsers/lists.js b/src/subParsers/lists.js index 48ba78f..4b40f66 100644 --- a/src/subParsers/lists.js +++ b/src/subParsers/lists.js @@ -3,7 +3,6 @@ */ showdown.subParser('lists', function (text, options, globals) { 'use strict'; - text = globals.converter._dispatch('lists.before', text, options, globals); /** * Process the contents of a single ordered or unordered list, splitting it @@ -78,7 +77,7 @@ showdown.subParser('lists', function (text, options, globals) { //
  • - - a
// So, to prevent it, we will put a marker (~A)in the beginning of the line // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser - item = item.replace(/^([-*+]|\d\.)[ \t]+[\s\n]*/g, function (wm2) { + item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) { return '~A' + wm2; }); @@ -101,7 +100,6 @@ showdown.subParser('lists', function (text, options, globals) { // now we need to remove the marker (~A) item = item.replace('~A', ''); - // we can finally wrap the line in list item tags item = '' + item + '\n'; return item; @@ -180,7 +178,6 @@ showdown.subParser('lists', function (text, options, globals) { // strip sentinel text = text.replace(/~0/, ''); - text = globals.converter._dispatch('lists.after', text, options, globals); return text; }); diff --git a/test/issues/#312.spaced-dashes-followed-by-char4.html b/test/issues/#312.spaced-dashes-followed-by-char4.html new file mode 100644 index 0000000..e60553a --- /dev/null +++ b/test/issues/#312.spaced-dashes-followed-by-char4.html @@ -0,0 +1,3 @@ +
    +
  • - - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd
  • +
diff --git a/test/issues/#312.spaced-dashes-followed-by-char4.md b/test/issues/#312.spaced-dashes-followed-by-char4.md new file mode 100644 index 0000000..e8d2acc --- /dev/null +++ b/test/issues/#312.spaced-dashes-followed-by-char4.md @@ -0,0 +1 @@ +- - - - -- - - - - - - -- - - - - - - - - - - - - - - - - - - - abcd