summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2016-08-05 21:29:15 +0200
committeruwetews <uwe.tews@googlemail.com>2016-08-05 21:29:15 +0200
commit25ad0b3b5a25d9ef341c8ab8a75168de0fe4c986 (patch)
tree142eeacc51d25524ebcb83be85492dba0050cab5
parent04301645d60b08a00c919536640586cf6a8c1573 (diff)
downloadsmarty-25ad0b3b5a25d9ef341c8ab8a75168de0fe4c986.tar.gz
smarty-25ad0b3b5a25d9ef341c8ab8a75168de0fe4c986.tar.bz2
smarty-25ad0b3b5a25d9ef341c8ab8a75168de0fe4c986.zip
- updated error checking at template and config default handler
-rw-r--r--change_log.txt1
-rw-r--r--libs/Smarty.class.php2
-rw-r--r--libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php14
-rw-r--r--libs/sysplugins/smarty_template_compiled.php5
-rw-r--r--libs/sysplugins/smarty_template_config.php19
-rw-r--r--libs/sysplugins/smarty_template_source.php3
6 files changed, 33 insertions, 11 deletions
diff --git a/change_log.txt b/change_log.txt
index cc785ebc..509c51d0 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,6 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)
05.08.2015
- bugfix compiling of templates failed when the Smarty delimiter did contain '/' https://github.com/smarty-php/smarty/issues/264
+ - updated error checking at template and config default handler
04.08.2015
- improvement move template function source parameter into extension
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 2d9fc29d..15241504 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
- const SMARTY_VERSION = '3.1.30-dev/90';
+ const SMARTY_VERSION = '3.1.30-dev/91';
/**
* define variable scopes
diff --git a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php
index 17a579b9..73e8f627 100644
--- a/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php
+++ b/libs/sysplugins/smarty_internal_method_registerdefaulttemplatehandler.php
@@ -44,6 +44,8 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
* get default content from template or config resource handler
*
* @param Smarty_Template_Source $source
+ *
+ * @throws \SmartyException
*/
public static function _getDefaultTemplate(Smarty_Template_Source $source)
{
@@ -59,12 +61,22 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
$source->exists = is_file($_return);
if ($source->exists) {
$source->timestamp = filemtime($_return);
+ } else {
+ throw new SmartyException("Default handler: Unable to load " .
+ ($source->isConfig ? 'config' : 'template') .
+ " default file '{$_return}' for '{$source->type}:{$source->name}'");
}
- $source->filepath = $_return;
+ $source->name = $source->filepath = $_return;
$source->uid = sha1($source->filepath);
} elseif ($_return === true) {
$source->content = $_content;
+ $source->exists = true;
+ $source->uid = $source->name = sha1($_content);
$source->handler = Smarty_Resource::load($source->smarty, 'eval');
+ } else {
+ $source->exists = false;
+ throw new SmartyException('Default handler: No ' . ($source->isConfig ? 'config' : 'template') .
+ " default content for '{$source->type}:{$source->name}'");
}
}
} \ No newline at end of file
diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php
index 4de3aac6..832c8e1f 100644
--- a/libs/sysplugins/smarty_template_compiled.php
+++ b/libs/sysplugins/smarty_template_compiled.php
@@ -146,6 +146,11 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
*/
public function render(Smarty_Internal_Template $_template)
{
+ // checks if template exists
+ if (!$_template->source->exists) {
+ $type = $_template->source->isConfig ? 'config' : 'template';
+ throw new SmartyException("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'");
+ }
if ($_template->smarty->debugging) {
if (!isset($_template->smarty->_debug)) {
$_template->smarty->_debug = new Smarty_Internal_Debug();
diff --git a/libs/sysplugins/smarty_template_config.php b/libs/sysplugins/smarty_template_config.php
index 57d30e3a..44cdba6f 100644
--- a/libs/sysplugins/smarty_template_config.php
+++ b/libs/sysplugins/smarty_template_config.php
@@ -8,7 +8,7 @@
*/
/**
- * Smarty Connfig Resource Data Object
+ * Smarty Config Resource Data Object
* Meta Data Container for Template Files
*
* @package Smarty
@@ -75,21 +75,24 @@ class Smarty_Template_Config extends Smarty_Template_Source
$template_resource = null)
{
static $_incompatible_resources = array('extends' => true, 'php' => true);
- $template_resource = $_template->template_resource;
+ if ($_template) {
+ $smarty = $_template->smarty;
+ $template_resource = $_template->template_resource;
+ }
if (empty($template_resource)) {
- throw new SmartyException('Missing config name');
+ throw new SmartyException('Source: Missing name');
}
- // parse resource_name, load resource handler
- list($name, $type) =
- Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
+ // parse resource_name, load resource handler
+ list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[ $type ])) {
throw new SmartyException ("Unable to use resource '{$type}' for config");
}
- $source = new Smarty_Template_Config($_template->smarty, $template_resource, $type, $name);
+ $source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template);
- if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
+ if (!$source->exists && isset($smarty->default_config_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
+ $source->handler->populate($source, $_template);
}
return $source;
}
diff --git a/libs/sysplugins/smarty_template_source.php b/libs/sysplugins/smarty_template_source.php
index d066e0c3..fdb3deaa 100644
--- a/libs/sysplugins/smarty_template_source.php
+++ b/libs/sysplugins/smarty_template_source.php
@@ -163,7 +163,7 @@ class Smarty_Template_Source
$template_resource = $_template->template_resource;
}
if (empty($template_resource)) {
- throw new SmartyException('Missing template name');
+ throw new SmartyException('Source: Missing name');
}
// parse resource_name, load resource handler, identify unique resource name
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
@@ -180,6 +180,7 @@ class Smarty_Template_Source
$source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
+ $source->handler->populate($source, $_template);
}
return $source;
}