From b8eb8784d45162dea2fd939ef585e787dcbb3a1f Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Wed, 20 May 2015 04:26:29 +0200 Subject: [PATCH] - bugfix output filter trimwhitespace could run into the pcre.backtrack_limit on large output (code.google issue 220) --- change_log.txt | 1 + libs/plugins/outputfilter.trimwhitespace.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/change_log.txt b/change_log.txt index 2bbe3879c..42a4648f8 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@  ===== 3.1.24.dev ===== (xx.xx.2015) 19.05.2015 - bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39 + - bugfix output filter trimwhitespace could run into the pcre.backtrack_limit on large output (code.google issue 220) 18.05.2015 - improvement introduce shortcuts in lexer/parser rules for most frequent terms for higher diff --git a/libs/plugins/outputfilter.trimwhitespace.php b/libs/plugins/outputfilter.trimwhitespace.php index 62ab4e776..ad35d11a2 100644 --- a/libs/plugins/outputfilter.trimwhitespace.php +++ b/libs/plugins/outputfilter.trimwhitespace.php @@ -45,7 +45,7 @@ function smarty_outputfilter_trimwhitespace($source) // capture html elements not to be messed with $_offset = 0; - if (preg_match_all('#<(script|pre|textarea)[^>]*>.*?#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { + if (preg_match_all('#(]*>.*?]*>)|(]*>.*?]*>)|(]*>.*?]*>)#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { foreach ($matches as $match) { $store[] = $match[0][0]; $_length = strlen($match[0][0]); @@ -62,7 +62,7 @@ function smarty_outputfilter_trimwhitespace($source) // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2', // remove spaces between attributes (but not in attribute values!) - '#(([a-z0-9]\s*=\s*(["\'])[^\3]*?\3)|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \4', + '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', // note: for some very weird reason trim() seems to remove spaces inside attributes. // maybe a \0 byte or something is interfering? '#^\s+<#Ss' => '<',