diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21977687..e27b60bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: - os: ubuntu-latest php-version: "8.0" compiler: jit + - os: ubuntu-latest + php-version: "8.1" + compiler: jit steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index f5d51ec5..695c17f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - PHP 8.1 deprecation notices in demo/plugins/cacheresource.pdo.php [#706](https://github.com/smarty-php/smarty/issues/706) +## [4.1.0] - 2022-02-06 + ### Added - PHP8.1 compatibility [#713](https://github.com/smarty-php/smarty/pull/713) diff --git a/README.md b/README.md index 404ef673..782f0b2c 100644 --- a/README.md +++ b/README.md @@ -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.0. +Smarty can be run with PHP 7.1 to PHP 8.1. ## Installation Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/). diff --git a/docs/getting-started.md b/docs/getting-started.md index cd21b96a..de55ffe8 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -2,7 +2,7 @@ What is Smarty? ============== ## Requirements -Smarty can be run with PHP 7.1 to PHP 8.0. +Smarty can be run with PHP 7.1 to PHP 8.1. ## Installation Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/). diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 2058524e..0abbe6a7 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -98,7 +98,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '4.0.4'; + const SMARTY_VERSION = '4.1.0'; /** * define variable scopes */ diff --git a/libs/plugins/function.math.php b/libs/plugins/function.math.php index fd5b3d16..8560e944 100644 --- a/libs/plugins/function.math.php +++ b/libs/plugins/function.math.php @@ -69,7 +69,7 @@ function smarty_function_math($params, $template) // Adapted from https://www.php.net/manual/en/function.eval.php#107377 $number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number $functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))'; - $operators = '[+\/*\^%-]'; // Allowed math operators + $operators = '[,+\/*\^%-]'; // Allowed math operators $regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)+\)|\((?1)+\)))(?:'.$operators.'(?1))?)+$/'; if (!preg_match($regexp, $equation)) { diff --git a/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php b/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php index 645c0a40..82255644 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php @@ -52,6 +52,22 @@ class MathTest extends PHPUnit_Smarty $this->assertEquals($expected, $this->smarty->fetch($tpl)); } + public function testMathMaxFunctionParameters() + { + $this->smarty->disableSecurity(); + $expected = max(0, 2) . ' -- ' . max(0, 2, 3); + $tpl = $this->smarty->createTemplate('eval:{$x = 0}{$y = 2}{$z = 3}{math equation="max(x, y)" x=$x y=$y} -- {math equation="max(x, y, z)" x=$x y=$y z=$z}'); + $this->assertEquals($expected, $this->smarty->fetch($tpl)); + } + + public function testMathMinFunctionParameters() + { + $this->smarty->disableSecurity(); + $expected = min(1, 2) . ' -- ' . min(1, 2, 0); + $tpl = $this->smarty->createTemplate('eval:{$x = 1}{$y = 2}{$z = 0}{math equation="min(x, y)" x=$x y=$y} -- {math equation="min(x, y, z)" x=$x y=$y z=$z}'); + $this->assertEquals($expected, $this->smarty->fetch($tpl)); + } + public function testSyntaxSin() { $this->smarty->disableSecurity();