Skip to content

Commit

Permalink
Merge branch 'master' into feature/php-8.4-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Visualq committed Oct 9, 2024
2 parents 9a5ba78 + a1b4c9c commit e9be58a
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 24 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- windows-latest

php-version:
- "7.2"
Expand Down Expand Up @@ -52,7 +53,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Override PHP ini values for JIT compiler
if: matrix.compiler == 'jit'
Expand All @@ -68,15 +69,15 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: vendor
key: v5r2-${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
v5r1-${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install dependencies
uses: php-actions/composer@v6
run: composer install

- name: Run make
run: make -B
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.4.1] - 2024-08-29


- Enable (and fix) unit tests for Windows [#1046](https://github.com/smarty-php/smarty/pull/1046)
- Fix the use of "extends:" to define the inheritance tree on Windows [#1018](https://github.com/smarty-php/smarty/issues/1018)

## [5.4.0] - 2024-08-14
- Fixing forced OpCache invalidation on every template include, which is resulting in fast raising wasted OpCache memory [#1007](https://github.com/smarty-php/smarty/issues/1007)
- Improvement of auto-escaping [#1030](https://github.com/smarty-php/smarty/pull/1030)


## [5.3.1] - 2024-06-16
- Fixed error when using section with nocache [#1034](https://github.com/smarty-php/smarty/issues/1034)

Expand Down
1 change: 0 additions & 1 deletion changelog/1030.md

This file was deleted.

6 changes: 5 additions & 1 deletion src/Resource/ExtendsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public function getContent(Source $source)
*/
public function getBasename(Source $source)
{
return str_replace(':', '.', basename($source->getResourceName()));
$search = array(':');
if (\Smarty\Smarty::$_IS_WINDOWS) {
$search = array(':', '|');
}
return str_replace($search, '.', basename($source->getResourceName()));
}

/*
Expand Down
9 changes: 6 additions & 3 deletions src/Resource/FilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ public function populate(Source $source, ?Template $_template = null) {
* @param Source $source source object
*/
public function populateTimestamp(Source $source) {
if (!$source->exists && $path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
$source->timestamp = $source->exists = is_file($path);
$path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig);
if (!$source->exists) {
$source->exists = ($path !== false && is_file($path));
}
if ($source->exists && $path) {
if ($source->exists && $path !== false) {
$source->timestamp = filemtime($path);
} else {
$source->timestamp = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Smarty.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Smarty extends \Smarty\TemplateBase {
/**
* smarty version
*/
const SMARTY_VERSION = '5.3.1';
const SMARTY_VERSION = '5.4.1';

/**
* define caching modes
Expand Down
21 changes: 12 additions & 9 deletions src/Template/Compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function compileAndLoad(Template $_smarty_tpl) {
if ($this->exists && !$_smarty_tpl->getSmarty()->force_compile
&& !($_smarty_tpl->compile_check && $_smarty_tpl->getSource()->getTimeStamp() > $this->getTimeStamp())
) {
$this->loadCompiledTemplate($_smarty_tpl);
$this->loadCompiledTemplate($_smarty_tpl, false);
}

if (!$this->isValid) {
Expand Down Expand Up @@ -241,16 +241,19 @@ private function write(Template $_template, $code) {
* HHVM requires a workaround because of a PHP incompatibility
*
* @param Template $_smarty_tpl do not change/remove variable name, is used by compiled template
* @param bool $invalidateCachedFiles forces a revalidation of the file in opcache or apc cache (if available)
*
*/
private function loadCompiledTemplate(Template $_smarty_tpl) {

if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
private function loadCompiledTemplate(Template $_smarty_tpl, bool $invalidateCachedFiles = true) {

if ($invalidateCachedFiles) {
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
}
if (defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($this->filepath));
Expand Down
17 changes: 13 additions & 4 deletions tests/UnitTests/CacheResourceTests/File/CacheResourceFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
class CacheResourceFileTest extends CacheResourceTestCommon
{

private $directorySeparator;

public function setUp(): void
{
$this->setUpSmarty(__DIR__);
parent::setUp();
$this->directorySeparator = preg_quote(DIRECTORY_SEPARATOR, '/');
$this->smarty->setCachingType('filetest');
}

Expand All @@ -38,7 +41,8 @@ public function testGetCachedFilepathSubDirs()
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');

$this->assertRegExp('/.*\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath);
$pattern = '/.*' . $this->directorySeparator . '([a-f0-9]{2}' . $this->directorySeparator . '){3}.*\.php/';
$this->assertRegExp($pattern, $tpl->getCached()->filepath);
}

/**
Expand All @@ -51,7 +55,8 @@ public function testGetCachedFilepathCacheId()
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');

$this->assertRegExp('/.*\/foo\/bar\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath);
$pattern = '/.*' . $this->directorySeparator . 'foo' . $this->directorySeparator . 'bar' . $this->directorySeparator . '([a-f0-9]{2}' . $this->directorySeparator . '){3}.*\.php/';
$this->assertRegExp($pattern, $tpl->getCached()->filepath);
}

/**
Expand All @@ -63,7 +68,9 @@ public function testGetCachedFilepathCompileId()
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertRegExp('/.*\/blar\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath);

$pattern = '/.*' . $this->directorySeparator . 'blar' . $this->directorySeparator . '([a-f0-9]{2}' . $this->directorySeparator . '){3}.*\.php/';
$this->assertRegExp($pattern, $tpl->getCached()->filepath);
}

/**
Expand All @@ -75,7 +82,9 @@ public function testGetCachedFilepathCacheIdCompileId()
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertRegExp('/.*\/foo\/bar\/blar\\/([a-f0-9]{2}\/){3}.*.php/', $tpl->getCached()->filepath);

$pattern = '/.*' . $this->directorySeparator . 'foo' . $this->directorySeparator . 'bar' . $this->directorySeparator . 'blar' . $this->directorySeparator . '([a-f0-9]{2}' . $this->directorySeparator . '){3}.*\.php/';
$this->assertRegExp($pattern, $tpl->getCached()->filepath);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/TemplateSource/NullCoalescingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class NullCoalescingTest extends PHPUnit_Smarty {

public function setUp(): void
{
$this->setUpSmarty('/tmp');
$this->setUpSmarty(sys_get_temp_dir());
$this->cleanDirs();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,28 @@ public function testIllegalFunctionName() {
$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'));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{function blah}gribus{/function}
{call name=blah}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{function name=blah}gribus{/function}
{blah}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{function blah}gribus{/function}
{blah}
2 changes: 1 addition & 1 deletion tests/UnitTests/TemplateSource/TernaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TernaryTest extends PHPUnit_Smarty {

public function setUp(): void
{
$this->setUpSmarty('/tmp');
$this->setUpSmarty(sys_get_temp_dir());
$this->cleanDirs();
}

Expand Down

0 comments on commit e9be58a

Please sign in to comment.