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

PHP 8.1 compatibility (without IntlDateFormatter) #713

Merged
merged 4 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"

compiler:
- default
Expand Down
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_cacheresource_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $e
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
clearstatcache(true, $cached->lock_id);
if (is_file($cached->lock_id)) {
clearstatcache(true, $cached->lock_id ?? '');
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you closed previous one, carry the discussion:

Copy link
Contributor Author

@thirsch thirsch Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we continue the discussion here? My last answer was:

Personally I agree with your point, but IMO it's out of scope of this change. What the original author tried to do is "doing whatever php < 8.1 would do". So another pr should cope with the issue.

But we can also remove the change in line #199 as it's only a deprecation warning in php 8.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no say of this, as I'm not the maintainer.

personally, I would carry the fix to separate PR and hope it gets merged sooner as the change is smaller.

ps: edit #199 to be backticks as it links to bogus ticket, or replace with link to source

$t = filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
} else {
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_compile_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n";
$output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n";
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_config_file_compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function compileTemplate(Smarty_Internal_Template $template)
}
// template header code
$template_header =
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . date("Y-m-d H:i:s") .
"\n";
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n";
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_runtime_codeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function create(
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
}
$output = "<?php\n";
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . strftime("%Y-%m-%d %H:%M:%S") .
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . date("Y-m-d H:i:s") .
"\n from '" . str_replace('*/', '* /', $_template->source->filepath) . "' */\n\n";
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_templatecompilerbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ public function trigger_template_error($args = null, $line = null, $tagline = nu
flush();
}
$e = new SmartyCompilerException($error_text);
$e->line = $line;
$e->setLine($line);
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
$e->desc = $args;
$e->template = $this->template->source->filepath;
Expand Down
10 changes: 5 additions & 5 deletions libs/sysplugins/smartycompilerexception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public function __toString()
}

/**
* The line number of the template error
*
* @type int|null
* @param int $line
*/
public $line = null;

public function setLine($line)
{
$this->line = $line;
}
/**
* The template source snippet relating to the error
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected function doClearCacheAssertion($a, $b)

public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
{
return str_replace('#', $tpl->getTemplateVars('test'), $text);
$replace = $tpl->getTemplateVars('test');
return str_replace('#', $replace ?? '', $text);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function stream_write($data)
$v = &$GLOBALS[$this->varname];
$l = strlen($data);
$p = &$this->position;
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);

return $l;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/UnitTests/SecurityTests/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ public function testNotTrustedUri()

/**
* In security mode, accessing $smarty.template_object should be illegal.
* @expectedException SmartyCompilerException
*/
public function testSmartyTemplateObject() {
$this->expectException(SmartyCompilerException::class);
$this->smarty->display('string:{$smarty.template_object}');
}

Expand Down Expand Up @@ -416,7 +416,7 @@ public function stream_write($data)
$v = &$GLOBALS[$this->varname];
$l = strlen($data);
$p = &$this->position;
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);

return $l;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ public function dataTestSpacing()

/**
* Test handling of function names that are a security risk
* @expectedException SmartyCompilerException
*/
public function testIllegalFunctionName() {
$this->expectException(SmartyCompilerException::class);
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function stream_write($data)
$v = &$GLOBALS[$this->varname];
$l = strlen($data);
$p = &$this->position;
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);

return $l;
}
Expand Down