mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-10 15:31:28 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
665b216f61 | ||
|
|
6f4025b038 | ||
|
|
4c39c543d4 | ||
|
|
9fee14e7af | ||
|
|
afbcf3250d | ||
|
|
87c479c87e | ||
|
|
892dc33907 | ||
|
|
d02ef6652a |
+2
-11
@@ -6,22 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- `$smarty->muteUndefinedOrNullWarnings()` now also mutes PHP7 notices for undefined array indexes [#736](https://github.com/smarty-php/smarty/issues/736)
|
|
||||||
- `$smarty->muteUndefinedOrNullWarnings()` now treats undefined vars and array access of a null or false variables
|
|
||||||
equivalent across all supported PHP versions
|
|
||||||
|
|
||||||
## [4.3.0] - 2022-11-22
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- PHP8.2 compatibility [#775](https://github.com/smarty-php/smarty/pull/775)
|
- PHP8.2 compatibility [#775](https://github.com/smarty-php/smarty/pull/775)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Include docs and demo in the releases [#799](https://github.com/smarty-php/smarty/issues/799)
|
- Include docs and demo in the releases [#799](https://github.com/smarty-php/smarty/issues/799)
|
||||||
- Using PHP functions as modifiers now 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)
|
- Using PHP functions as modifiers now 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)
|
||||||
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)
|
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)
|
||||||
- Support umask when writing (template) files and set dir permissions to 777 [#548](https://github.com/smarty-php/smarty/issues/548) [#819](https://github.com/smarty-php/smarty/issues/819)
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514)
|
- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514)
|
||||||
- Fixed recursion and out of memory errors when caching in complicated template set-ups using inheritance and includes [#801](https://github.com/smarty-php/smarty/pull/801)
|
- Fixed recursion and out of memory errors when caching in complicated template set-ups using inheritance and includes [#801](https://github.com/smarty-php/smarty/pull/801)
|
||||||
@@ -32,7 +24,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586)
|
- Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586)
|
||||||
- Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581)
|
- Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581)
|
||||||
|
|
||||||
|
|
||||||
## [4.2.1] - 2022-09-14
|
## [4.2.1] - 2022-09-14
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
|
entrypoint: sh ./run-tests.sh
|
||||||
php71:
|
php71:
|
||||||
extends:
|
extends:
|
||||||
service: base
|
service: base
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '4.3.0';
|
const SMARTY_VERSION = '4.2.1';
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
*/
|
*/
|
||||||
@@ -1386,7 +1386,8 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutes errors for "undefined index", "undefined array key" and "trying to read property of null".
|
* Activates PHP7 compatibility mode:
|
||||||
|
* - converts E_WARNINGS for "undefined array key" and "trying to read property of null" errors to E_NOTICE
|
||||||
*
|
*
|
||||||
* @void
|
* @void
|
||||||
*/
|
*/
|
||||||
@@ -1395,7 +1396,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if Smarty will mute errors for "undefined index", "undefined array key" and "trying to read property of null".
|
* Indicates if PHP7 compatibility mode is set.
|
||||||
* @bool
|
* @bool
|
||||||
*/
|
*/
|
||||||
public function isMutingUndefinedOrNullWarnings(): bool {
|
public function isMutingUndefinedOrNullWarnings(): bool {
|
||||||
|
|||||||
@@ -66,15 +66,12 @@ class Smarty_Internal_ErrorHandler
|
|||||||
*/
|
*/
|
||||||
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
|
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
|
||||||
{
|
{
|
||||||
if ($this->allowUndefinedVars && preg_match(
|
if ($this->allowUndefinedVars && $errstr == 'Attempt to read property "value" on null') {
|
||||||
'/^(Attempt to read property ".+?" on null|Trying to get property (\'.+?\' )?of non-object)/',
|
|
||||||
$errstr
|
|
||||||
)) {
|
|
||||||
return; // suppresses this error
|
return; // suppresses this error
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->allowUndefinedArrayKeys && preg_match(
|
if ($this->allowUndefinedArrayKeys && preg_match(
|
||||||
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type (null|bool))/',
|
'/^(Undefined array key|Trying to access array offset on value of type null)/',
|
||||||
$errstr
|
$errstr
|
||||||
)) {
|
)) {
|
||||||
return; // suppresses this error
|
return; // suppresses this error
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
{
|
{
|
||||||
$_error_reporting = error_reporting();
|
$_error_reporting = error_reporting();
|
||||||
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||||
|
$old_umask = umask(0);
|
||||||
$_dirpath = dirname($_filepath);
|
$_dirpath = dirname($_filepath);
|
||||||
// if subdirs, create dir structure
|
// if subdirs, create dir structure
|
||||||
if ($_dirpath !== '.') {
|
if ($_dirpath !== '.') {
|
||||||
@@ -36,7 +37,7 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
// loop if concurrency problem occurs
|
// loop if concurrency problem occurs
|
||||||
// see https://bugs.php.net/bug.php?id=35326
|
// see https://bugs.php.net/bug.php?id=35326
|
||||||
while (!is_dir($_dirpath)) {
|
while (!is_dir($_dirpath)) {
|
||||||
if (@mkdir($_dirpath, 0777, true)) {
|
if (@mkdir($_dirpath, 0771, true)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
@@ -84,7 +85,8 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
throw new SmartyException("unable to write file {$_filepath}");
|
throw new SmartyException("unable to write file {$_filepath}");
|
||||||
}
|
}
|
||||||
// set file permissions
|
// set file permissions
|
||||||
@chmod($_filepath, 0666 & ~umask());
|
chmod($_filepath, 0644);
|
||||||
|
umask($old_umask);
|
||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1131,12 +1131,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
echo ob_get_clean();
|
echo ob_get_clean();
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
$e = new SmartyCompilerException(
|
$e = new SmartyCompilerException($error_text);
|
||||||
$error_text,
|
$e->setLine($line);
|
||||||
0,
|
|
||||||
$this->template->source->filepath,
|
|
||||||
$line
|
|
||||||
);
|
|
||||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
||||||
$e->desc = $args;
|
$e->desc = $args;
|
||||||
$e->template = $this->template->source->filepath;
|
$e->template = $this->template->source->filepath;
|
||||||
|
|||||||
@@ -7,33 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
class SmartyCompilerException extends SmartyException
|
class SmartyCompilerException extends SmartyException
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The constructor of the exception
|
|
||||||
*
|
|
||||||
* @param string $message The Exception message to throw.
|
|
||||||
* @param int $code The Exception code.
|
|
||||||
* @param string|null $filename The filename where the exception is thrown.
|
|
||||||
* @param int|null $line The line number where the exception is thrown.
|
|
||||||
* @param Throwable|null $previous The previous exception used for the exception chaining.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
string $message = "",
|
|
||||||
int $code = 0,
|
|
||||||
?string $filename = null,
|
|
||||||
?int $line = null,
|
|
||||||
Throwable $previous = null
|
|
||||||
) {
|
|
||||||
parent::__construct($message, $code, $previous);
|
|
||||||
|
|
||||||
// These are optional parameters, should be be overridden only when present!
|
|
||||||
if ($filename) {
|
|
||||||
$this->file = $filename;
|
|
||||||
}
|
|
||||||
if ($line) {
|
|
||||||
$this->line = $line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -49,7 +22,6 @@ class SmartyCompilerException extends SmartyException
|
|||||||
{
|
{
|
||||||
$this->line = $line;
|
$this->line = $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The template source snippet relating to the error
|
* The template source snippet relating to the error
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,13 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
Help()
|
||||||
|
{
|
||||||
|
# Display Help
|
||||||
|
echo "Runs PHPUnit tests for all PHP versions supported by this version of Smarty."
|
||||||
|
echo
|
||||||
|
echo "Syntax: $0 [-e|h]"
|
||||||
|
echo "options:"
|
||||||
|
echo "e Exclude a group of unit tests, e.g. -e 'slow'"
|
||||||
|
echo "h Print this Help."
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
Exclude=""
|
||||||
|
|
||||||
|
# Get the options
|
||||||
|
while getopts ":he:" option; do
|
||||||
|
case $option in
|
||||||
|
e) # Exclude
|
||||||
|
echo $OPTARG
|
||||||
|
Exclude=$OPTARG;;
|
||||||
|
h) # display Help
|
||||||
|
Help
|
||||||
|
exit;;
|
||||||
|
\?) # Invalid option
|
||||||
|
echo "Error: Invalid option"
|
||||||
|
exit;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z $Exclude ];
|
||||||
|
then
|
||||||
|
Entrypoint="./run-tests.sh"
|
||||||
|
else
|
||||||
|
Entrypoint="./run-tests.sh $Exclude"
|
||||||
|
fi
|
||||||
|
|
||||||
# Runs tests for all supported PHP versions
|
# Runs tests for all supported PHP versions
|
||||||
# Usage examples:
|
docker-compose run --entrypoint "$Entrypoint" php71 && \
|
||||||
# - ./run-tests-for-all-php-versions.sh --group 20221124
|
docker-compose run --entrypoint "$Entrypoint" php72 && \
|
||||||
# - ./run-tests-for-all-php-versions.sh --exclude-group slow
|
docker-compose run --entrypoint "$Entrypoint" php73 && \
|
||||||
|
docker-compose run --entrypoint "$Entrypoint" php74 && \
|
||||||
docker-compose run php71 ./run-tests.sh $@ && \
|
docker-compose run --entrypoint "$Entrypoint" php80 && \
|
||||||
docker-compose run php72 ./run-tests.sh $@ && \
|
docker-compose run --entrypoint "$Entrypoint" php81
|
||||||
docker-compose run php73 ./run-tests.sh $@ && \
|
|
||||||
docker-compose run php74 ./run-tests.sh $@ && \
|
|
||||||
docker-compose run php80 ./run-tests.sh $@ && \
|
|
||||||
docker-compose run php81 ./run-tests.sh $@
|
|
||||||
|
|||||||
+10
-7
@@ -1,10 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
composer update
|
||||||
|
|
||||||
# Runs composer update, echoes php version and runs PHPUnit
|
php -r 'echo "\nPHP version " . phpversion() . ". ";';
|
||||||
# Usage examples:
|
|
||||||
# - ./run-tests.sh --group 20221124
|
|
||||||
# - ./run-tests.sh --exclude-group slow
|
|
||||||
|
|
||||||
composer update --quiet
|
if [ -z $1 ];
|
||||||
#php -r 'echo "\nPHP version " . phpversion() . ". ";'
|
then
|
||||||
php ./vendor/phpunit/phpunit/phpunit $@
|
echo "Running all unit tests.\n"
|
||||||
|
php ./vendor/phpunit/phpunit/phpunit
|
||||||
|
else
|
||||||
|
echo "Running all unit tests, except tests marked with @group $1.\n"
|
||||||
|
php ./vendor/phpunit/phpunit/phpunit --exclude-group $1
|
||||||
|
fi
|
||||||
@@ -88,12 +88,14 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testUndefinedSimpleVar() {
|
public function testUndefinedSimpleVar() {
|
||||||
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b');
|
$tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b');
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUndefinedArrayIndex() {
|
public function testUndefinedArrayIndex() {
|
||||||
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef}def{/if}b');
|
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef}def{/if}b');
|
||||||
$tpl->assign('ar', []);
|
$tpl->assign('ar', []);
|
||||||
@@ -101,6 +103,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testUndefinedArrayIndexDeep() {
|
public function testUndefinedArrayIndexDeep() {
|
||||||
|
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
$this->smarty->muteUndefinedOrNullWarnings();
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef.nope.neither}def{/if}b');
|
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef.nope.neither}def{/if}b');
|
||||||
$tpl->assign('ar', []);
|
$tpl->assign('ar', []);
|
||||||
@@ -130,19 +133,5 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
|||||||
$this->assertTrue($exceptionThrown);
|
$this->assertTrue($exceptionThrown);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUsingNullAsAnArrayIsMuted() {
|
|
||||||
$this->smarty->setErrorReporting(E_ALL);
|
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $undef.k}def{/if}b');
|
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUsingFalseAsAnArrayIsMuted() {
|
|
||||||
$this->smarty->setErrorReporting(E_ALL);
|
|
||||||
$this->smarty->muteUndefinedOrNullWarnings();
|
|
||||||
$tpl = $this->smarty->createTemplate('string:a{if $nottrue.k}def{/if}b');
|
|
||||||
$this->smarty->assign('nottrue', false);
|
|
||||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user