Optimized string matching for escaped quotes
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Mar 2018 22:53:24 +0000 (23:53 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Mar 2018 22:53:24 +0000 (23:53 +0100)
The new regex is more efficient, because it tries to match as long as
possible using repetitions of a character class, instead of repetitions
of an alternation, leading to fewer internal states.

wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php

index bd084db77a7eb8d6a86be1b1d65f8c497a495dcf..810c47dcfb198ef67788013e21820e7ca59decc6 100644 (file)
@@ -179,7 +179,7 @@ abstract class Highlighter extends SingletonFactory {
                        $closing = preg_quote($closing);
                        
                        if ($quotedEscapeSequence) {
-                               $quotesRegEx .= $opening.'(?>[^'.$closing.$quotedEscapeSequence.']|'.$quotedEscapeSequence.'.)*'.$closing;
+                               $quotesRegEx .= $opening.'(?>[^'.$closing.$quotedEscapeSequence.']+|('.$quotedEscapeSequence.'.)+)*'.$closing;
                        }
                        else {
                                $quotesRegEx .= $opening.'(?>[^'.$closing.$quotedEscapeSequence.'])*'.$closing;