1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Adjustment to FileCompiler to improve detection of false positive end-of-PHP blocks

This commit is contained in:
Ryan Cramer
2017-01-06 11:16:26 -05:00
parent 8d97815110
commit afd0e8bc95

View File

@@ -247,7 +247,18 @@ class FileCompiler extends Wire {
foreach($phpBlocks as $key => $phpBlock) {
$pos = strpos($phpBlock, $phpClose);
if($pos !== false) $phpBlock = substr($phpBlock, 0, $pos);
if($pos !== false) {
$closeBlock = substr($phpBlock, $phpClose + 2);
if(strrpos($closeBlock, '{') && strrpos($closeBlock, '}') && strrpos($closeBlock, '=')
&& strrpos($closeBlock, '(') && strrpos($closeBlock, ')')
&& preg_match('/\sif\s*\(/', $closeBlock)
&& preg_match('/\$[_a-zA-Z][_a-zA-Z0-9]+/', $closeBlock)) {
// closeBlock still looks a lot like PHP, leave $phpBlock as-is
// happens when for example a phpClose is within a PHP string
} else {
$phpBlock = substr($phpBlock, 0, $pos);
}
}
$this->rawPHP .= $phpOpen . $phpBlock . $phpClose . "\n";
}