Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/706
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Feb 6, 2022
2 parents 0d2c38b + f903489 commit 18d3e56
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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/).
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Expand Up @@ -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/).
Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion libs/plugins/function.math.php
Expand Up @@ -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)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/UnitTests/TemplateSource/ValueTests/Math/MathTest.php
Expand Up @@ -52,6 +52,22 @@ public function testMultipleOperators()
$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();
Expand Down

0 comments on commit 18d3e56

Please sign in to comment.