From: Alexander Ebert Date: Fri, 4 Dec 2015 17:42:39 +0000 (+0100) Subject: Minor improvements to php highlighter X-Git-Tag: 2.1.9~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3b2f7e0b491bfd1c9461653bc62fa9a1f5e0ee80;p=GitHub%2FWoltLab%2FWCF.git Minor improvements to php highlighter --- diff --git a/wcfsetup/install/files/lib/system/bbcode/highlighter/PhpHighlighter.class.php b/wcfsetup/install/files/lib/system/bbcode/highlighter/PhpHighlighter.class.php index 349be299ab..9ccdec5bc1 100644 --- a/wcfsetup/install/files/lib/system/bbcode/highlighter/PhpHighlighter.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/highlighter/PhpHighlighter.class.php @@ -49,8 +49,17 @@ class PhpHighlighter extends Highlighter { // remove added php tags if ($phpTagsAdded) { - $regex = new Regex('([^\\2]*)(<\?php )(.*)( .*\?>)([^\\4]*)', Regex::CASE_INSENSITIVE | Regex::DOT_ALL); - $highlightedCode = $regex->replace($highlightedCode, '\\1\\3\\5'); + // the opening and closing PHP tags were added previously, hence we actually do + // know that the first (last for the closing tag) occurence is the one inserted + // by us. The previously used regex was bad because it was significantly slower + // and could easily hit the backtrace limit for larger inputs + $openingTag = mb_strpos($highlightedCode, '<?php '); + $closingTag = mb_strrpos($highlightedCode, '?>'); + $tmp = mb_substr($highlightedCode, 0, $openingTag); + $tmp .= mb_substr($highlightedCode, $openingTag + 14, $closingTag - $openingTag - 14); + $tmp .= mb_substr($highlightedCode, $closingTag + 5); + + $highlightedCode = $tmp; } // remove breaks