mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-04 20:44:13 +02:00
Compare commits
20 Commits
issue_1074
...
v4.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
| f4152e9b81 | |||
| 5d0dd09632 | |||
| 9d559827fd | |||
| 5e2a9fbb26 | |||
| 9614a59199 | |||
| ee58a2173b | |||
| 29dd621b53 | |||
| de1bc77f7f | |||
| 326b2da8da | |||
| e0cbbdf6ea | |||
| b4bbc17f1c | |||
| 6e067ed327 | |||
| 3931d8f54b | |||
| d8c1dfe56e | |||
| 6887e55ded | |||
| 642fd69fea | |||
| 17a7d6fb5b | |||
| b96a5c3953 | |||
| 2ff66e0fcc | |||
| d6c4274822 |
@@ -32,6 +32,7 @@ jobs:
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
- "8.2"
|
||||
- "8.3"
|
||||
|
||||
compiler:
|
||||
- default
|
||||
@@ -46,7 +47,9 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.2"
|
||||
compiler: jit
|
||||
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.3"
|
||||
compiler: jit
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
@@ -6,8 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [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
|
||||
- PHP8.3 support [#925](https://github.com/smarty-php/smarty/issues/925)
|
||||
|
||||
### Fixed
|
||||
- Incorrect compilation of expressions when escape_html=true [#930](https://github.com/smarty-php/smarty/pull/930)
|
||||
|
||||
## [4.3.4] - 2023-09-14
|
||||
|
||||
## [4.3.3] - 2023-09-14
|
||||
|
||||
### Fixed
|
||||
- `|strip_tags` does not work if the input is 0 [#890](https://github.com/smarty-php/smarty/issues/890)
|
||||
- Use of negative numbers in {math} equations [#895](https://github.com/smarty-php/smarty/issues/895)
|
||||
|
||||
## [4.3.2] - 2023-07-19
|
||||
|
||||
|
||||
@@ -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.2.
|
||||
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/).
|
||||
|
||||
@@ -42,3 +42,8 @@ services:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php82/Dockerfile
|
||||
php83:
|
||||
extends:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php83/Dockerfile
|
||||
@@ -1,7 +1,7 @@
|
||||
# Getting started
|
||||
|
||||
## Requirements
|
||||
Smarty can be run with PHP 7.1 to PHP 8.2.
|
||||
Smarty can be run with PHP 7.1 to PHP 8.3.
|
||||
|
||||
## Installation
|
||||
Smarty can be installed with [Composer](https://getcomposer.org/).
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# Upgrading from an older version
|
||||
|
||||
## Upgrading from v3 to v4
|
||||
|
||||
Smarty 4 is mostly identical to Smarty 3. Most notably, it adds support for PHP8 and drops support for PHP7.0 and below.
|
||||
Additionally, some deprecated features that have long been discouraged have been dropped from the language.
|
||||
|
||||
### Muting PHP8 warnings
|
||||
If you simultaneously upgrade Smarty to v4 van PHP to v8, you may notice your error logs filling up with warnings about undefined or null template vars
|
||||
due to a change in how PHP handles these. This may be helpful to spot errors, but if you find this annoying, you can use
|
||||
`$smarty->muteUndefinedOrNullWarnings()` to make Smarty convert these warnings into notices.
|
||||
|
||||
### ASP tags
|
||||
You can no longer user ASP-style tags like `<% %>` and `<%= %>` in your templates.
|
||||
Replace them with `{...}` tags.
|
||||
|
||||
### SmartyBC
|
||||
Check your codebase for `SmartyBC`.
|
||||
We have dropped deprecated API calls that where only accessible through the SmartyBC class.
|
||||
|
||||
### No more embedded PHP
|
||||
We have completely dropped support for `{php}` and `{include_php}` tags and embedded PHP in templates.
|
||||
Check your templates for this, and rewrite any embedded PHP blocks, by moving logic to your PHP files or by
|
||||
creating a [plugin function](./programmers/plugins/plugins-functions.md).
|
||||
|
||||
### Other changes
|
||||
|
||||
Search your code for the following changes:
|
||||
|
||||
- `SMARTY_RESOURCE_CHAR_SET` and `SMARTY_RESOURCE_DATE_FORMAT` constants have been removed
|
||||
- `Smarty::muteExpectedErrors` and `Smarty::unmuteExpectedErrors` API methods have been removed
|
||||
- `Smarty::getVariable` method has been removed. Use [Smarty::getTemplateVars](programmers/api-functions/api-get-template-vars.md) instead.
|
||||
- [Smarty::registerResource](programmers/api-functions/api-register-resource.md) no longer accepts an array of callback functions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '4.3.2';
|
||||
const SMARTY_VERSION = '4.4.1';
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
|
||||
@@ -67,7 +67,7 @@ function smarty_function_math($params, $template)
|
||||
$equation = preg_replace('/\s+/', '', $equation);
|
||||
|
||||
// Adapted from https://www.php.net/manual/en/function.eval.php#107377
|
||||
$number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
|
||||
$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
|
||||
$regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)*\)|\((?1)*\)))(?:'.$operators.'(?1))?)+$/';
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
function smarty_modifier_implode($values, $separator = '')
|
||||
{
|
||||
if (is_array($separator)) {
|
||||
return implode((string) ($values ?? ''), (array) $separator);
|
||||
}
|
||||
return implode((string) ($separator ?? ''), (array) $values);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
function smarty_modifiercompiler_json_encode($params) {
|
||||
return 'json_encode(' . $params[0] . (isset($params[1]) ? ', (int) ' . $params[1] : '') . ')';
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
function smarty_modifiercompiler_substr($params) {
|
||||
return 'substr((string) ' . $params[0] . ', (int) ' . $params[1] .
|
||||
(isset($params[2]) ? ', (int) ' . $params[2] : '') . ')';
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
// autoescape html
|
||||
if ($compiler->template->smarty->escape_html) {
|
||||
$output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
|
||||
$output = "htmlspecialchars((string) ({$output}), ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
|
||||
}
|
||||
// loop over registered filters
|
||||
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
|
||||
|
||||
@@ -94,7 +94,7 @@ class Smarty_Internal_ErrorHandler
|
||||
}
|
||||
|
||||
if ($this->allowUndefinedArrayKeys && preg_match(
|
||||
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type)/',
|
||||
'/^(Undefined index|Undefined array key|Trying to access array offset on)/',
|
||||
$errstr
|
||||
)) {
|
||||
return; // suppresses this error
|
||||
|
||||
@@ -85,7 +85,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template
|
||||
*
|
||||
* @return string
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function render(Smarty_Internal_Template $_template)
|
||||
|
||||
+5
-4
@@ -8,13 +8,14 @@ else
|
||||
fi
|
||||
|
||||
git checkout -b "release/$1"
|
||||
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
|
||||
sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" libs/Smarty.class.php
|
||||
|
||||
git add CHANGELOG.md libs/Smarty.class.php
|
||||
php utilities/update-changelog.php $1
|
||||
php utilities/update-smarty-version-number.php $1
|
||||
|
||||
git add changelog CHANGELOG.md libs/Smarty.class.php
|
||||
git commit -m "version bump"
|
||||
|
||||
git checkout master
|
||||
git checkout support/4.3
|
||||
git pull
|
||||
git merge --no-ff "release/$1"
|
||||
git branch -d "release/$1"
|
||||
|
||||
+3
-1
@@ -26,7 +26,9 @@ markdown_extensions:
|
||||
|
||||
nav:
|
||||
- Home: 'index.md'
|
||||
- 'Getting started': 'getting-started.md'
|
||||
- 'Getting started':
|
||||
- Introduction: 'getting-started.md'
|
||||
- 'Upgrading from an older version': 'upgrading.md'
|
||||
- 'Designers':
|
||||
- 'Basic Syntax':
|
||||
- Introduction: 'designers/language-basic-syntax/index.md'
|
||||
|
||||
@@ -10,4 +10,6 @@ docker-compose run php72 ./run-tests.sh $@ && \
|
||||
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 $@
|
||||
docker-compose run php81 ./run-tests.sh $@ && \
|
||||
docker-compose run php82 ./run-tests.sh $@ && \
|
||||
docker-compose run php83 ./run-tests.sh $@
|
||||
|
||||
@@ -30,4 +30,36 @@ class AutoEscapeTest extends PHPUnit_Smarty
|
||||
$tpl->assign('foo', '<a@b.c>');
|
||||
$this->assertEquals("<a@b.c>", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test 'escapeHtml' property
|
||||
* @group issue906
|
||||
*/
|
||||
public function testAutoEscapeDoesNotEscapeFunctionPlugins()
|
||||
{
|
||||
$this->smarty->registerPlugin(
|
||||
Smarty::PLUGIN_FUNCTION,
|
||||
'horizontal_rule',
|
||||
function ($params, $smarty) { return "<hr>"; }
|
||||
);
|
||||
$tpl = $this->smarty->createTemplate('eval:{horizontal_rule}');
|
||||
$this->assertEquals("<hr>", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
* test 'escapeHtml' property
|
||||
* @group issue906
|
||||
*/
|
||||
public function testAutoEscapeDoesNotEscapeBlockPlugins()
|
||||
{
|
||||
$this->smarty->registerPlugin(
|
||||
Smarty::PLUGIN_BLOCK,
|
||||
'paragraphify',
|
||||
function ($params, $content) { return $content == null ? null : "<p>".$content."</p>"; }
|
||||
);
|
||||
$tpl = $this->smarty->createTemplate('eval:{paragraphify}hi{/paragraphify}');
|
||||
$this->assertEquals("<p>hi</p>", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests of modifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for modifier tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class PluginModifierImplodeTest extends PHPUnit_Smarty
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testDefault()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{""|implode:$v}');
|
||||
$tpl->assign("v", ["1", "2"]);
|
||||
$this->assertEquals("12", $this->smarty->fetch($tpl));
|
||||
}
|
||||
public function testWithSeparator()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{","|implode:$v}');
|
||||
$tpl->assign("v", ["a", "b"]);
|
||||
$this->assertEquals("a,b", $this->smarty->fetch($tpl));
|
||||
}
|
||||
public function testInConditional()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{if implode("", $v) == "abc"}good{else}bad{/if}');
|
||||
$tpl->assign("v", ['a','b','c']);
|
||||
$this->assertEquals("good", $this->smarty->fetch($tpl));
|
||||
}
|
||||
public function testInConditionalWithSeparator()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{if implode("-", $v) == "a-b-c"}good{else}bad{/if}');
|
||||
$tpl->assign("v", ['a','b','c']);
|
||||
$this->assertEquals("good", $this->smarty->fetch($tpl));
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests of modifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for modifier tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class PluginModifierJsonEncodeTest extends PHPUnit_Smarty
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForDefault
|
||||
*/
|
||||
public function testDefault($value, $expected)
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{$v|json_encode}');
|
||||
$tpl->assign("v", $value);
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForDefault
|
||||
*/
|
||||
public function testDefaultAsFunction($value, $expected)
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{json_encode($v)}');
|
||||
$tpl->assign("v", $value);
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function dataForDefault() {
|
||||
return [
|
||||
["abc", '"abc"'],
|
||||
[["abc"], '["abc"]'],
|
||||
[["abc",["a"=>2]], '["abc",{"a":2}]'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForForceObject
|
||||
*/
|
||||
public function testForceObject($value, $expected)
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{$v|json_encode:16}');
|
||||
$tpl->assign("v", $value);
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataForForceObject
|
||||
*/
|
||||
public function testForceObjectAsFunction($value, $expected)
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{json_encode($v,16)}');
|
||||
$tpl->assign("v", $value);
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function dataForForceObject() {
|
||||
return [
|
||||
["abc", '"abc"'],
|
||||
[["abc"], '{"0":"abc"}'],
|
||||
[["abc",["a"=>2]], '{"0":"abc","1":{"a":2}}'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests of modifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for modifier tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class PluginModifierSubstrTest extends PHPUnit_Smarty
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testDefault()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{$v|substr:1}');
|
||||
$tpl->assign("v", "abc");
|
||||
$this->assertEquals("bc", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testTwoArguments()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{$v|substr:1:1}');
|
||||
$tpl->assign("v", "abc");
|
||||
$this->assertEquals("b", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testNegativeOffset()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{$v|substr:-1}');
|
||||
$tpl->assign("v", "abc");
|
||||
$this->assertEquals("c", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testInConditional()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{if substr($v, -1) == "c"}good{else}bad{/if}');
|
||||
$tpl->assign("v", "abc");
|
||||
$this->assertEquals("good", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -101,6 +101,14 @@ class MathTest extends PHPUnit_Smarty
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testNegativeNumbers()
|
||||
{
|
||||
$this->smarty->disableSecurity();
|
||||
$expected = "-19 -- 4.1";
|
||||
$tpl = $this->smarty->createTemplate('eval:{$x = 4}{$y = 5.5}{math equation="-2.0*(x+y)" x=$x y=$y} -- {math equation="-20.5 / -5"}');
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testSyntaxFormat()
|
||||
{
|
||||
$this->smarty->disableSecurity();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
FROM php:8.3-cli
|
||||
|
||||
## 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
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// This takes the *.md files in changelog/ dir and inserts them
|
||||
// right below the '## [Unreleased]' marker in CHANGELOG.md
|
||||
|
||||
$path_to_main_changelog = 'CHANGELOG.md';
|
||||
$marker = '## [Unreleased]';
|
||||
$changelog_files_pattern = 'changelog/*.md';
|
||||
$new_version = $argv[1];
|
||||
|
||||
$file_contents = file_get_contents($path_to_main_changelog);
|
||||
|
||||
foreach (glob($changelog_files_pattern) as $filename) {
|
||||
$content_to_insert = file_get_contents($filename);
|
||||
|
||||
if (!endsWithNewline($content_to_insert)) {
|
||||
$content_to_insert .= "\n";
|
||||
}
|
||||
|
||||
$file_contents = str_replace(
|
||||
$marker,
|
||||
$marker . $content_to_insert,
|
||||
$file_contents
|
||||
);
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
|
||||
// add the version number and date
|
||||
$file_contents = str_replace(
|
||||
$marker,
|
||||
$marker . sprintf("\n\n## [%s] - %s\n", $new_version, date('Y-m-d')),
|
||||
$file_contents
|
||||
);
|
||||
|
||||
file_put_contents($path_to_main_changelog, $file_contents);
|
||||
|
||||
|
||||
function endsWithNewline($str): bool
|
||||
{
|
||||
return preg_match('/[\r\n]$/', $str) === 1;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
// This takes the Smarty class file and updates the SMARTY_VERSION constant
|
||||
|
||||
$path_to_smarty_class = 'libs/Smarty.class.php';
|
||||
$pattern = "/const SMARTY_VERSION = '[^']+'/";
|
||||
$replacement = "const SMARTY_VERSION = '" . $argv[1] . "'";
|
||||
|
||||
$file_contents = preg_replace($pattern, $replacement, file_get_contents($path_to_smarty_class));
|
||||
|
||||
file_put_contents($path_to_smarty_class, $file_contents);
|
||||
Reference in New Issue
Block a user