From 3b2f7e0b491bfd1c9461653bc62fa9a1f5e0ee80 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 4 Dec 2015 18:42:39 +0100 Subject: [PATCH] Minor improvements to php highlighter --- .../bbcode/highlighter/PhpHighlighter.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 -- 2.20.1