Compare commits

..

10 Commits

58 changed files with 195 additions and 392 deletions
-4
View File
@@ -33,7 +33,6 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
compiler:
- default
@@ -51,9 +50,6 @@ jobs:
- os: ubuntu-latest
php-version: "8.3"
compiler: jit
- os: ubuntu-latest
php-version: "8.4"
compiler: jit
steps:
- name: Checkout
uses: actions/checkout@v3
+2 -20
View File
@@ -6,32 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [4.5.5] - 2024-11-21
- Support the deprecations introduced in PHP 8.4 and added tests for PHP 8.4 [#1084](https://github.com/smarty-php/smarty/pull/1084)
## [4.5.4] - 2024-08-14
- Fixed that using `count()` would trigger a deprecation notice. [#813](https://github.com/smarty-php/smarty/issues/813)
## [4.5.3] - 2024-05-28
- Fixed a code injection vulnerability in extends-tag. This addresses CVE-2024-35226.
## [4.5.2] - 2024-04-06
- Fixed argument must be passed by reference error introduced in v4.5.1 [#964](https://github.com/smarty-php/smarty/issues/964)
## [4.5.1] - 2024-03-18
### Changed
- Using unregistered static class methods in expressions now also triggers a deprecation notice because we will drop support for this in the next major release [#813](https://github.com/smarty-php/smarty/issues/813)
## [4.5.0] - 2024-03-18
- (this release accidentally didn't contain any changes, fixed in 4.5.1)
## [4.4.1] - 2024-02-26
- Fixed internal release-tooling
## [4.4.0] - 2024-02-26
### Changed
- Using the `|implode`, `|json_encode` and `|substr` modifiers does not generate a deprecation warning anymore as they will continue to be supported in v5 [#939](https://github.com/smarty-php/smarty/issues/939)
### Added
+1 -1
View File
@@ -7,7 +7,7 @@ Smarty is a template engine for PHP, facilitating the separation of presentation
Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it.
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.4.
Smarty can be run with PHP 7.1 to PHP 8.3.
## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
+3 -3
View File
@@ -13,12 +13,12 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$uid = '';
$sources = array();
+1 -6
View File
@@ -46,9 +46,4 @@ services:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php83/Dockerfile
php84:
extends:
service: base
build:
dockerfile: ./utilities/testrunners/php84/Dockerfile
dockerfile: ./utilities/testrunners/php83/Dockerfile
@@ -178,14 +178,14 @@ The above example will output:
</p>
<p>
name: Jack Jones<br />
home: 777-555-5555<br />
cell: 888-555-5555<br />
home phone: 777-555-5555<br />
cell phone: 888-555-5555<br />
e-mail: jack@myexample.com
</p>
<p>
name: Jane Munson<br />
home: 000-555-5555<br />
cell: 123456<br />
home phone: 000-555-5555<br />
cell phone: 123456<br />
e-mail: jane@myexample.com
</p>
```
+1 -1
View File
@@ -1,7 +1,7 @@
# Getting started
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.4.
Smarty can be run with PHP 7.1 to PHP 8.3.
## Installation
Smarty can be installed with [Composer](https://getcomposer.org/).
+7 -7
View File
@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '4.5.5';
const SMARTY_VERSION = '4.4.1';
/**
* define variable scopes
*/
@@ -1036,11 +1036,11 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Get unique template id
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty_Internal_Template|null $template
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty_Internal_Template $template
*
* @return string
* @throws \SmartyException
@@ -1050,7 +1050,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$cache_id = null,
$compile_id = null,
$caching = null,
?Smarty_Internal_Template $template = null
Smarty_Internal_Template $template = null
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
+4 -4
View File
@@ -44,15 +44,15 @@ abstract class Smarty_CacheResource
/**
* Read the cached template and process header
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
abstract public function process(
Smarty_Internal_Template $_template,
?Smarty_Template_Cached $cached = null,
Smarty_Template_Cached $cached = null,
$update = false
);
@@ -124,15 +124,15 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
?Smarty_Template_Cached $cached = null,
Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
@@ -88,15 +88,15 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Read the cached template and process the header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param boolean $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
?Smarty_Template_Cached $cached = null,
Smarty_Template_Cached $cached = null,
$update = false
) {
if (!$cached) {
@@ -88,15 +88,15 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
/**
* Read the cached template and process its header
*
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached|null $cached cached object
* @param bool $update flag if called because cache update
* @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(
Smarty_Internal_Template $_smarty_tpl,
?Smarty_Template_Cached $cached = null,
Smarty_Template_Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
*
* @var array
*/
public $optional_attributes = array();
public $optional_attributes = array('extends_resource');
/**
* Attribute definition: Overwrites base class.
@@ -62,7 +62,29 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
}
// add code to initialize inheritance
$this->registerInit($compiler, true);
$this->compileEndChild($compiler, $_attr[ 'file' ]);
$file = trim($_attr[ 'file' ], '\'"');
if (strlen($file) > 8 && substr($file, 0, 8) === 'extends:') {
// generate code for each template
$files = array_reverse(explode('|', substr($file, 8)));
$i = 0;
foreach ($files as $file) {
if ($file[ 0 ] === '"') {
$file = trim($file, '".');
} else {
$file = "'{$file}'";
}
$i++;
if ($i === count($files) && isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
$this->compileInclude($compiler, $file);
}
if (!isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
} else {
$this->compileEndChild($compiler, $_attr[ 'file' ]);
}
$compiler->has_code = false;
return '';
}
@@ -93,4 +115,44 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
'') . ");\n?>"
);
}
/**
* Add code for including subtemplate to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param string $template subtemplate name
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->compileTag(
'include',
array(
$template,
array('scope' => 'parent')
)
)
);
}
/**
* Create source code for {extends} from source components array
*
* @param \Smarty_Internal_Template $template
*
* @return string
*/
public static function extendsSourceArrayCode(Smarty_Internal_Template $template)
{
$resources = array();
foreach ($template->source->components as $source) {
$resources[] = $source->resource;
}
return $template->smarty->left_delimiter . 'extends file=\'extends:' . join('|', $resources) .
'\' extends_resource=true' . $template->smarty->right_delimiter;
}
}
+2 -2
View File
@@ -190,7 +190,7 @@ abstract class Smarty_Internal_Data
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars($varName = null, ?Smarty_Internal_Data $_ptr = null, $searchParents = true)
public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
{
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
}
@@ -200,7 +200,7 @@ abstract class Smarty_Internal_Data
*
* @param \Smarty_Internal_Data|null $data
*/
public function _mergeVars(?Smarty_Internal_Data $data = null)
public function _mergeVars(Smarty_Internal_Data $data = null)
{
if (isset($data)) {
if (!empty($this->tpl_vars)) {
@@ -24,14 +24,14 @@ class Smarty_Internal_Method_CreateData
* @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
*
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty|null $parent next higher level of Smarty
* variables
* @param string $name optional data block name
* @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
* @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty
* variables
* @param string $name optional data block name
*
* @return \Smarty_Data data object
*/
public function createData(Smarty_Internal_TemplateBase $obj, ?Smarty_Internal_Data $parent = null, $name = null)
public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null)
{
/* @var Smarty $smarty */
$smarty = $obj->_getSmartyObj();
@@ -24,17 +24,17 @@ class Smarty_Internal_Method_GetTemplateVars
* @api Smarty::getTemplateVars()
* @link https://www.smarty.net/docs/en/api.get.template.vars.tpl
*
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty|null $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars(
Smarty_Internal_Data $data,
$varName = null,
?Smarty_Internal_Data $_ptr = null,
Smarty_Internal_Data $_ptr = null,
$searchParents = true
) {
if (isset($varName)) {
@@ -87,7 +87,7 @@ class Smarty_Internal_Method_GetTemplateVars
public function _getVariable(
Smarty_Internal_Data $data,
$varName,
?Smarty_Internal_Data $_ptr = null,
Smarty_Internal_Data $_ptr = null,
$searchParents = true,
$errorEnable = true
) {
@@ -22,11 +22,11 @@ class Smarty_Internal_Resource_Eval extends Smarty_Resource_Recompiled
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name);
$source->timestamp = $source->exists = true;
@@ -28,11 +28,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @throws SmartyException
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$uid = '';
$sources = array();
@@ -21,11 +21,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @throws \SmartyException
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
@@ -93,12 +93,12 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
* build template filepath by traversing the template_dir array
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return string fully qualified filepath
* @throws SmartyException
*/
protected function buildFilepath(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$file = $source->name;
// absolute file ?
@@ -23,11 +23,11 @@ class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
if (strpos($source->resource, '://') !== false) {
$source->filepath = $source->resource;
@@ -22,11 +22,11 @@ class Smarty_Internal_Resource_String extends Smarty_Resource
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
$source->timestamp = $source->exists = true;
@@ -17,11 +17,11 @@ class Smarty_Internal_Runtime_CodeFrame
/**
* Create code frame for compiled and cached templates
*
* @param Smarty_Internal_Template $_template
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty_Internal_TemplateCompilerBase|null $compiler
* @param Smarty_Internal_Template $_template
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string
*/
@@ -30,7 +30,7 @@ class Smarty_Internal_Runtime_CodeFrame
$content = '',
$functions = '',
$cache = false,
?Smarty_Internal_TemplateCompilerBase $compiler = null
Smarty_Internal_TemplateCompilerBase $compiler = null
) {
// build property code
$properties[ 'version' ] = Smarty::SMARTY_VERSION;
@@ -168,7 +168,7 @@ class Smarty_Internal_Runtime_Inheritance
public function process(
Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
?Smarty_Internal_Block $parent = null
Smarty_Internal_Block $parent = null
) {
if ($block->hide && !isset($block->child)) {
return;
+1 -1
View File
@@ -149,7 +149,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function __construct(
$template_resource,
Smarty $smarty,
?Smarty_Internal_Data $_parent = null,
Smarty_Internal_Data $_parent = null,
$_cache_id = null,
$_compile_id = null,
$_caching = null,
@@ -386,7 +386,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function compileTemplate(
Smarty_Internal_Template $template,
$nocache = null,
?Smarty_Internal_TemplateCompilerBase $parent_compiler = null
Smarty_Internal_TemplateCompilerBase $parent_compiler = null
) {
// get code frame of compiled template
$_compiled_code = $template->smarty->ext->_codeFrame->create(
@@ -407,9 +407,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Compile template source and run optional post filter
*
* @param \Smarty_Internal_Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty_Internal_TemplateCompilerBase|null $parent_compiler
* @param \Smarty_Internal_Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return string
* @throws \Exception
@@ -417,7 +417,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function compileTemplateSource(
Smarty_Internal_Template $template,
$nocache = null,
?Smarty_Internal_TemplateCompilerBase $parent_compiler = null
Smarty_Internal_TemplateCompilerBase $parent_compiler = null
) {
try {
// save template object in compiler class
@@ -455,29 +455,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->smarty->_current_file = $this->template->source->filepath;
// get template source
if (!empty($this->template->source->components)) {
$_compiled_code = '<?php $_smarty_tpl->_loadInheritance(); $_smarty_tpl->inheritance->init($_smarty_tpl, true); ?>';
$i = 0;
$reversed_components = array_reverse($this->template->getSource()->components);
foreach ($reversed_components as $source) {
$i++;
if ($i === count($reversed_components)) {
$_compiled_code .= '<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl); ?>';
}
$_compiled_code .= $this->compileTag(
'include',
[
var_export($source->resource, true),
['scope' => 'parent'],
]
);
}
$_compiled_code = $this->postFilter($_compiled_code, $this->template);
// we have array of inheritance templates by extends: resource
// generate corresponding source code sequence
$_content =
Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template);
} else {
// get template source
$_content = $this->template->source->getContent();
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
}
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
if (!empty($this->required_plugins[ 'compiled' ]) || !empty($this->required_plugins[ 'nocache' ])) {
$_compiled_code = '<?php ' . $this->compileRequiredPlugins() . "?>\n" . $_compiled_code;
}
@@ -654,18 +640,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
return $func_name . '(' . $parameter[ 0 ] . ')';
}
} else {
if (
!$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
&& !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
&& !in_array($name, ['time', 'join', 'is_array', 'in_array', 'count'])
) {
trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
}
return $name . '(' . implode(',', $parameter) . ')';
$first_param = array_shift($parameter);
$modifier = array_merge(array($name), $parameter);
// Now, compile the function call as a modifier
return $this->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => array($modifier),
'value' => $first_param
)
);
}
} else {
$this->trigger_template_error("unknown function '{$name}'");
+8 -8
View File
@@ -165,16 +165,16 @@ abstract class Smarty_Resource
* wrapper for backward compatibility to versions < 3.1.22
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty|null $smarty smarty object
* @param string $template_resource resource identifier
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return \Smarty_Template_Source Source Object
* @throws \SmartyException
*/
public static function source(
?Smarty_Internal_Template $_template = null,
?Smarty $smarty = null,
Smarty_Internal_Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
return Smarty_Template_Source::load($_template, $smarty, $template_resource);
@@ -193,10 +193,10 @@ abstract class Smarty_Resource
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
abstract public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null);
abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
/**
* populate Source Object with timestamp and exists from Resource
+3 -3
View File
@@ -42,10 +42,10 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
$source->uid = sha1($source->type . ':' . $source->name);
+5 -5
View File
@@ -63,16 +63,16 @@ class Smarty_Template_Config extends Smarty_Template_Source
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty|null $smarty smarty object
* @param string $template_resource resource identifier
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Config Source Object
* @throws SmartyException
*/
public static function load(
?Smarty_Internal_Template $_template = null,
?Smarty $smarty = null,
Smarty_Internal_Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
static $_incompatible_resources = array('extends' => true, 'php' => true);
+5 -5
View File
@@ -148,16 +148,16 @@ class Smarty_Template_Source
* initialize Source Object for given resource
* Either [$_template] or [$smarty, $template_resource] must be specified
*
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty|null $smarty smarty object
* @param string $template_resource resource identifier
* @param Smarty_Internal_Template $_template template object
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Source Source Object
* @throws SmartyException
*/
public static function load(
?Smarty_Internal_Template $_template = null,
?Smarty $smarty = null,
Smarty_Internal_Template $_template = null,
Smarty $smarty = null,
$template_resource = null
) {
if ($_template) {
+1 -1
View File
@@ -21,7 +21,7 @@ class SmartyCompilerException extends SmartyException
int $code = 0,
?string $filename = null,
?int $line = null,
?Throwable $previous = null
Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
+1 -1
View File
@@ -15,7 +15,7 @@ php utilities/update-smarty-version-number.php $1
git add changelog CHANGELOG.md libs/Smarty.class.php
git commit -m "version bump"
git checkout support/4
git checkout support/4.3
git pull
git merge --no-ff "release/$1"
git branch -d "release/$1"
+1 -2
View File
@@ -14,5 +14,4 @@ $COMPOSE_CMD run --rm php74 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php80 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php81 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php82 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php83 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php84 ./run-tests.sh $@
$COMPOSE_CMD run --rm php83 ./run-tests.sh $@
+1 -1
View File
@@ -68,7 +68,7 @@ class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
*/
public static function setUpBeforeClass(): void
{
error_reporting(E_ALL);
error_reporting(E_ALL & ~E_STRICT);
self::$init = true;
self::$pluginsdir =self::getSmartyPluginsDir();
}
@@ -5,10 +5,10 @@ class Smarty_Resource_Filetest extends Smarty_Internal_Resource_File
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
parent::populate($source, $_template);
if ($source->exists) {
@@ -12,7 +12,7 @@
class Smarty_Resource_Db4 extends Smarty_Resource
{
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = 'db4:';
$source->uid = sha1($source->resource);
@@ -38,10 +38,10 @@ class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
/**
* populate Source Object with meta data from Resource
*
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template|null $_template template object
* @param Smarty_Template_Source $source source object
* @param Smarty_Internal_Template $_template template object
*/
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$segment = '';
if ($this->segment) {
@@ -12,7 +12,7 @@
class Smarty_Resource_Db extends Smarty_Resource_Recompiled {
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null) {
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
$source->filepath = 'db:';
$source->uid = sha1($source->resource);
$source->timestamp = 1000000000;
@@ -12,7 +12,7 @@
class Smarty_Resource_Db2 extends Smarty_Resource_Recompiled
{
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = 'db2:';
$source->uid = sha1($source->resource);
@@ -12,7 +12,7 @@
class Smarty_Resource_Db3 extends Smarty_Resource
{
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = 'db3:';
$source->uid = sha1($source->resource);
@@ -12,7 +12,7 @@
class Smarty_Resource_Db4 extends Smarty_Resource
{
public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$source->filepath = 'db4:';
$source->uid = sha1($source->resource);
@@ -152,10 +152,10 @@ class SecurityTest extends PHPUnit_Smarty
*/
public function testAllowedModifier1()
{
error_reporting(E_ALL);
error_reporting(E_ALL & E_STRICT);
$this->smarty->security_policy->allowed_modifiers = array('capitalize');
$this->assertEquals("Hello World", $this->smarty->fetch('string:{"hello world"|capitalize}'));
error_reporting(E_ALL);
error_reporting(E_ALL | E_STRICT);
}
public function testAllowedModifier2()
@@ -109,17 +109,4 @@ class GetTemplateVarsTest extends PHPUnit_Smarty
$this->assertEquals("bar2", $this->smarty->getTemplateVars('foo2', $data2, false));
$this->assertEquals("", $this->smarty->getTemplateVars('blar', $data2, false));
}
public function testSimpleCallReturnsArrayWithAllValues()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->assign('i', 3);
$vars = $this->smarty->getTemplateVars();
$this->assertArrayHasKey('foo', $vars);
$this->assertArrayHasKey('i', $vars);
$this->assertEquals('bar', $vars['foo']);
$this->assertEquals(3,$vars['i']);
}
}
@@ -1371,38 +1371,8 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
);
}
public function testBlockWithAssign() {
$this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl'));
}
/**
* Test escaping of file parameter
*/
public function testEscaping()
{
$this->expectException(SmartyException::class);
$this->expectExceptionMessageRegExp('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping.tpl'));
}
/**
* Test escaping of file parameter 2
*/
public function testEscaping2()
{
$this->expectException(SmartyException::class);
$this->expectExceptionMessageRegExp('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping2.tpl'));
}
/**
* Test escaping of file parameter 3
*/
public function testEscaping3()
{
$this->expectException(SmartyException::class);
$this->expectExceptionMessageRegExp('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping3.tpl'));
}
public function testBlockWithAssign() {
$this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl'));
}
}
@@ -1 +0,0 @@
{extends "extends:helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3, 4, 5, 6);}}?>"}
@@ -1 +0,0 @@
{extends 'extends:"helloworld.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3, 4, 5, 6);}}?>'}
@@ -1 +0,0 @@
{extends file='extends:"helloworld.tpl'|cat:"', var_dump(shell_exec('ls')), 1, 2, 3, 4, 5, 6);}}?>"}
@@ -82,18 +82,6 @@ class CompileIncludeTest extends PHPUnit_Smarty
$this->assertEquals('I1I2I3', $content, $text);
}
/**
* test template name escaping
*/
public function testIncludeFilenameEscaping()
{
$this->expectException(SmartyException::class);
$this->expectExceptionMessageRegExp('/Unable to load.*/');
$tpl = $this->smarty->createTemplate('test_include_security.tpl');
$content = $this->smarty->fetch($tpl);
$this->assertEquals("hello world", $content);
}
/**
* test standard output
*
@@ -1 +0,0 @@
{include file="helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3, 4, 5, 6);}}?>"}
@@ -148,37 +148,4 @@ class CompileSectionTest extends PHPUnit_Smarty
);
}
public function testNestedArrayAsLoopParameter()
{
$data = [
['name' => 'John Smith', 'home' => '555-555-5555',
'cell' => '666-555-5555', 'email' => 'john@myexample.com'],
['name' => 'Jack Jones', 'home' => '777-555-5555',
'cell' => '888-555-5555', 'email' => 'jack@myexample.com'],
['name' => 'Jane Munson', 'home' => '000-555-5555',
'cell' => '123456', 'email' => 'jane@myexample.com']
];
$this->smarty->assign('contacts',$data);
$result = $this->smarty->fetch('string:{section name=customer loop=$contacts}
name: {$contacts[customer].name}
home: {$contacts[customer].home}
cell: {$contacts[customer].cell}
e-mail: {$contacts[customer].email}
{/section}');
$this->assertEquals('name: John Smith
home: 555-555-5555
cell: 666-555-5555
e-mail: john@myexample.com
name: Jack Jones
home: 777-555-5555
cell: 888-555-5555
e-mail: jack@myexample.com
name: Jane Munson
home: 000-555-5555
cell: 123456
e-mail: jane@myexample.com
', $result);
}
}
@@ -438,31 +438,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
*/
public function testIllegalFunctionName() {
$this->expectException(SmartyCompilerException::class);
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
}
/**
* test shorthand function definition with regular call
*/
public function testShorthand1()
{
$this->assertEquals("gribus", $this->smarty->fetch('shorthand1.tpl'));
}
/**
* test normal function definition with shorthand call
*/
public function testShorthand2()
{
$this->assertEquals("gribus", $this->smarty->fetch('shorthand2.tpl'));
}
/**
* test shorthand function definition with shorthand call
*/
public function testShorthand3()
{
$this->assertEquals("gribus", $this->smarty->fetch('shorthand3.tpl'));
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
}
}
@@ -1,2 +0,0 @@
{function blah}gribus{/function}
{call name=blah}
@@ -1,2 +0,0 @@
{function name=blah}gribus{/function}
{blah}
@@ -1,2 +0,0 @@
{function blah}gribus{/function}
{blah}
@@ -247,7 +247,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
$this->smarty->assign('f', 3.14);
$errorMessage = '';
$output = '';
try {
$output = $this->smarty->fetch('string:' . $strTemplateSource);
@@ -283,7 +282,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
['{$a|substr:-1}', 'a', false],
['{$f|substr:-1}', '4', false],
['{$ar|count}', '2', false],
['{count($ar)}', '2', false],
['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314', false],
['{"-"|implode:$ar}', '1-2', false],
['{"-"|join:$ar}', '1-2', false],
@@ -299,12 +299,4 @@ class ScopeTest extends PHPUnit_Smarty
$this->smarty->assign('scope', 'none');
$r = $this->smarty->fetch('test_function_scope.tpl');
}
public function testFunctionScopeIsLocalByDefault()
{
$r = $this->smarty->fetch('string:{function name=test}{$var="b"}{/function}{$var="a"}{test}{$var}');
$this->assertEquals('a', $r);
}
}
@@ -32,11 +32,4 @@ class ExtendsIssue419Test extends PHPUnit_Smarty
$this->assertEquals('child', $this->smarty->fetch('extends:001_parent.tpl|001_child.tpl'));
}
public function testextendsSecurity()
{
$this->expectException(SmartyException::class);
$this->expectExceptionMessageRegExp('/Unable to load.*/');
$this->assertEquals('child', $this->smarty->fetch('string:{include "001_parent.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3, 4, 5, 6);}}?>"}'));
}
}
@@ -1,67 +0,0 @@
<?php
class ArgumentMustBePassedByReference961Test extends PHPUnit_Smarty
{
/**
* @group issue961
*/
public function testReset()
{
$smarty = new Smarty();
$smarty->registerPlugin('modifier', 'reset', 'reset');
$templateStr = "string:{reset(\$ar)}";
$smarty->assign('ar', [1,2,3]);
$this->assertEquals(
'1',
$smarty->fetch($templateStr)
);
}
/**
* @group issue961
* @deprecated
*/
public function testResetAsModifier()
{
$smarty = new Smarty();
try {
$templateStr = "string:{\$ar|reset}";
$smarty->assign('ar', [1,2,3]);
$this->assertEquals(
'1',
$smarty->fetch($templateStr)
);
} catch (Exception $e) {
}
}
/**
* @group issue961
*/
public function testResetInExpression()
{
$smarty = new Smarty();
$smarty->registerPlugin('modifier', 'reset', 'reset');
$templateStr = "string:{if reset(\$ar)}ok{/if}";
$smarty->assign('ar', [1,2,3]);
$this->assertEquals(
'ok',
$smarty->fetch($templateStr)
);
}
/**
* @group issue961
*/
public function testMatch()
{
$smarty = new Smarty();
$smarty->registerPlugin('modifier', 'preg_match', 'preg_match');
$templateStr = 'string:{assign var="match" value=null}{if preg_match(\'/([a-z]{4})/\', "a test", $match)}{$match.1}{/if}';
$this->assertEquals(
'test',
$smarty->fetch($templateStr)
);
}
}
-10
View File
@@ -1,10 +0,0 @@
FROM php:8.4-rc-cli-bullseye
## Basic utilities
RUN apt-get update -yqq && apt-get install -y curl apt-utils git zip unzip
## Composer
COPY ./utilities/testrunners/shared/install-composer.sh /root/install-composer.sh
WORKDIR /root
RUN sh ./install-composer.sh
RUN mv ./composer.phar /usr/local/bin/composer