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.
This commit is contained in:
parent
c85ce458ce
commit
7403ea6a6b
2 changed files with 10 additions and 28 deletions
26
vendor/plugins/maruku/lib/maruku/ext/div.rb
vendored
26
vendor/plugins/maruku/lib/maruku/ext/div.rb
vendored
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = /<([^:]+@[^:]+)>/
|
||||
|
|
Loading…
Reference in a new issue