[TASK] Fluid (Core): Regular Expression performance improvements
authorSebastian Kurfürst <sebastian@typo3.org>
Thu, 26 Aug 2010 08:13:15 +0000 (08:13 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Thu, 26 Aug 2010 08:13:15 +0000 (08:13 +0000)
In rare cases, on some systems (like mine), the
PCRE parser reproducably crashes if one passes very
long argument strings into it, or very complex ones.

With this patch, the parser is slightly modified
to decrease the use of backtracking; which then avoids
the crashes mostly.

typo3/sysext/fluid/Classes/Core/Parser/TemplateParser.php

index 970bc2c..78bc7d9 100644 (file)
@@ -42,7 +42,7 @@ class Tx_Fluid_Core_Parser_TemplateParser {
                                        (?:                                   # Begin tag arguments
                                                \s*[a-zA-Z0-9:]+                  # Argument Keys
                                                =                                 # =
-                                               (?:                               # either...
+                                               (?>                               # either... If we have found an argument, we will not back-track (That does the Atomic Bracket)
                                                        "(?:\\\"|[^"])*"              # a double-quoted string
                                                        |\'(?:\\\\\'|[^\'])*\'        # or a single quoted string
                                                )\s*                              #
@@ -71,7 +71,7 @@ class Tx_Fluid_Core_Parser_TemplateParser {
                                \s*
                                [a-zA-Z0-9:]+                             # The attribute name
                                =                                         # =
-                               (?:                                       # either...
+                               (?>                                       # either... # If we have found an argument, we will not back-track (That does the Atomic Bracket)
                                        "(?:\\\"|[^"])*"                      # a double-quoted string
                                        |\'(?:\\\\\'|[^\'])*\'                # or a single quoted string
                                )                                         #
@@ -102,7 +102,7 @@ class Tx_Fluid_Core_Parser_TemplateParser {
                                [a-zA-Z0-9:]+                            #
                        )                                            #
                        =                                            # =
-                       (?:                                          # obsolete I guess
+                       (?>                                          # If we have found an argument, we will not back-track (That does the Atomic Bracket)
                                (?P<ValueQuoted>                         # either...
                                        (?:"(?:\\\"|[^"])*")                 # a double-quoted string
                                        |(?:\'(?:\\\\\'|[^\'])*\')           # or a single quoted string