From 594dbf6aa7baed4d26023a75ae08c165b1363a63 Mon Sep 17 00:00:00 2001 From: Blackskyliner Date: Wed, 27 May 2015 08:39:51 +0200 Subject: [PATCH] Update Parser.php If an template was empty it threw an error, as fread expects $length to be greater than 0. Patched it with an additional check for actual filesize and fallback to an empty string if file is empty, also skip the processing if $code is empty. --- library/Rain/Tpl/Parser.php | 43 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/library/Rain/Tpl/Parser.php b/library/Rain/Tpl/Parser.php index 31b07bb..07f6c0b 100644 --- a/library/Rain/Tpl/Parser.php +++ b/library/Rain/Tpl/Parser.php @@ -123,25 +123,30 @@ public function compileFile( $this->templateInfo['template_filepath'] = $templateFilepath; // read the file - $this->templateInfo['code'] = $code = fread($fp, filesize($templateFilepath)); - - // xml substitution - $code = preg_replace("/<\?xml(.*?)\?>/s", /*config['php_enabled']) - $code = str_replace(array(""), array("<?", "?>"), $code); - - // xml re-substitution - $code = preg_replace_callback("/##XML(.*?)XML##/s", function( $match ) { - return "'; ?>"; - }, $code); - - $parsedCode = $this->compileTemplate($code, $isString = false, $templateBasedir, $templateDirectory, $templateFilepath); - $parsedCode = "" . $parsedCode; - - // fix the php-eating-newline-after-closing-tag-problem - $parsedCode = str_replace("?>\n", "?>\n\n", $parsedCode); + $filesize = filesize($templateFilepath); + $this->templateInfo['code'] = $code = $filesize > 0 ? fread($fp, $filesize) : ''; + + if (!empty($code)) { + // xml substitution + $code = preg_replace("/<\?xml(.*?)\?>/s", /*config['php_enabled']) + $code = str_replace(array(""), array("<?", "?>"), $code); + + // xml re-substitution + $code = preg_replace_callback("/##XML(.*?)XML##/s", function( $match ) { + return "'; ?>"; + }, $code); + + $parsedCode = $this->compileTemplate($code, $isString = false, $templateBasedir, $templateDirectory, $templateFilepath); + $parsedCode = "" . $parsedCode; + + // fix the php-eating-newline-after-closing-tag-problem + $parsedCode = str_replace("?>\n", "?>\n\n", $parsedCode); + } else { + $parsedCode = ''; + } // create directories if (!is_dir($this->config['cache_dir']))