Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handler should only allow notices etc in smarty templates, not beyond #840

Open
wants to merge 3 commits into
base: support/4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 30 additions & 21 deletions libs/sysplugins/smarty_internal_errorhandler.php
Expand Up @@ -37,6 +37,12 @@ class Smarty_Internal_ErrorHandler

private $previousErrorHandler = null;

private $smarty;

public function __construct(Smarty $smarty) {
$this->smarty = $smarty;
}

/**
* Enable error handler to intercept errors
*/
Expand Down Expand Up @@ -78,33 +84,36 @@ public function deactivate() {
*/
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
{
if (strpos($errfile, $this->smarty->getCompileDir()) === 0) {

if ($this->allowUndefinedVars && preg_match(
'/^(Attempt to read property "value" on null|Trying to get property (\'value\' )?of non-object)/',
$errstr
)) {
return; // suppresses this error
}
if ($this->allowUndefinedVars && preg_match(
'/^(Attempt to read property "value" on null|Trying to get property (\'value\' )?of non-object)/',
$errstr
)) {
return; // suppresses this error
}

if ($this->allowUndefinedProperties && preg_match(
'/^(Undefined property)/',
if ($this->allowUndefinedArrayKeys && preg_match(
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
$errstr
)) {
return; // suppresses this error
}
return; // suppresses this error
}

if ($this->allowUndefinedArrayKeys && preg_match(
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
$errstr
)) {
return; // suppresses this error
}
if ($this->allowDereferencingNonObjects && preg_match(
'/^Attempt to read property ".+?" on/',
$errstr
)) {
return; // suppresses this error
}

if ($this->allowUndefinedProperties && preg_match(
'/^(Undefined property)/',
$errstr
)) {
return; // suppresses this error
}

if ($this->allowDereferencingNonObjects && preg_match(
'/^Attempt to read property ".+?" on/',
$errstr
)) {
return; // suppresses this error
}

// pass all other errors through to the previous error handler or to the default PHP error handler
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_templatebase.php
Expand Up @@ -201,7 +201,7 @@ private function _execute($template, $cache_id, $compile_id, $parent, $function)
isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null;

if ($smarty->isMutingUndefinedOrNullWarnings()) {
$errorHandler = new Smarty_Internal_ErrorHandler();
$errorHandler = new Smarty_Internal_ErrorHandler($smarty);
$errorHandler->activate();
}

Expand Down