From 7403ea6a6bda6f9588fba84a228665b26d62b76c Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Fri, 27 Mar 2009 02:44:49 -0500 Subject: [PATCH] Don't be greedy! Maruku uses greedy Regexps in a number of places, which, in unfavourable circumstances, can lead to exponential slowdowns (an apparent hang). We worked around one such bug in Revision 355. Recently, Toby Bartels found another (in Table Header parsing). The "real" solution seems to be to make sure the Regexps are not greedy. (Thanks to Sam Ruby for spotting the problem!) Reverted the workaround in Revision 355, fixed Toby's bug, and several other similar Regexps. --- vendor/plugins/maruku/lib/maruku/ext/div.rb | 26 +++---------------- .../maruku/lib/maruku/input/type_detection.rb | 12 ++++----- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/vendor/plugins/maruku/lib/maruku/ext/div.rb b/vendor/plugins/maruku/lib/maruku/ext/div.rb index efb4e60b..c308a24e 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/div.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/div.rb @@ -10,28 +10,10 @@ #| +-------------------------------------------------- #+--------------------------------------------------- -## These cause Instiki to hang when it encounters -## -## +-- -## ###### Definition -## A _Froelicher Space_ is a triple $(X,C_X,F_X)$ -## =-- {: .num_defn #FroelicherSpace -## -## or -## -## +-- {: .num_defn #FroelicherSpace -## ###### Definition -## A _Froelicher Space_ is a triple $(X,C_X,F_X)$ -## =-- -# -#OpenDiv = /^[ ]{0,3}\+\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/ -#CloseDiv = /^[ ]{0,3}\=\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/ -# -## note these are not enough for parsing the above example: -## (but they don't produce a hang ...) -# -OpenDiv = /^[ ]{0,3}\+\-\-+\s*(.*)$/ -CloseDiv = /^[ ]{0,3}\=\-\-+\s*(.*)$/ +#OpenDiv = /^[ ]{0,3}\+\-\-+\s*(.*)$/ +#CloseDiv = /^[ ]{0,3}\=\-\-+\s*(.*)$/ +OpenDiv = /^[ ]{0,3}\+\-\-+\s*(\{([^{}]*?|".*?"|'.*?')*\})?\s*\-*\s*$/ +CloseDiv = /^[ ]{0,3}\=\-\-+\s*(\{([^{}]*?|".*?"|'.*?')*\})?\s*\-*\s*$/ StartPipe = /^[ ]{0,3}\|(.*)$/ # $1 is rest of line DecorativeClosing = OpenDiv diff --git a/vendor/plugins/maruku/lib/maruku/input/type_detection.rb b/vendor/plugins/maruku/lib/maruku/input/type_detection.rb index e019414c..cd91d6ef 100644 --- a/vendor/plugins/maruku/lib/maruku/input/type_detection.rb +++ b/vendor/plugins/maruku/lib/maruku/input/type_detection.rb @@ -74,9 +74,9 @@ module MaRuKu; module Strings # $1 = id $2 = attribute list - AttributeDefinitionList = /^\s{0,3}\{([\w\d\s]+)\}:\s*(.*)\s*$/ + AttributeDefinitionList = /^\s{0,3}\{([\w\d\s]+)\}:\s*(.*?)\s*$/ # - InlineAttributeList = /^\s{0,3}\{([:#\.].*)\}\s*$/ + InlineAttributeList = /^\s{0,3}\{([:#\.].*?)\}\s*$/ # Example: # ^:blah blah # ^: blah blah @@ -128,11 +128,11 @@ module MaRuKu; module Strings )? # title is optional }x - IncompleteLink = %r{^[ ]{0,3}\[([^\[\]]+)\]:\s*$} + IncompleteLink = %r{^[ ]{0,3}\[([^\[\]]+?)\]:\s*$} - HeaderWithId = /^(.*)\{\#([\w_-]+)\}\s*$/ + HeaderWithId = /^(.*?)\{\#([\w_-]+)\}\s*$/ - HeaderWithAttributes = /^(.*)\{(.*)\}\s*$/ + HeaderWithAttributes = /^(.*?)\{(.*?)\}\s*$/ # if contains a pipe, it could be a table header @@ -140,7 +140,7 @@ module MaRuKu; module Strings # -------------: Sep = /\s*(\:)?\s*-+\s*(\:)?\s*/ # | -------------:| ------------------------------ | - TableSeparator = %r{^(\|?#{Sep}\|?)+\s*$} + TableSeparator = %r{^(\|?#{Sep}\|?)+?\s*$} EMailAddress = /<([^:]+@[^:]+)>/