mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-04 04:24:18 +02:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f25dd94f9f | |||
| d1dcee0d9e | |||
| 8df47cf030 | |||
| 6f41b9bfc9 | |||
| 7d48d8692f | |||
| ca2be225d6 | |||
| 3b0b48ed3e | |||
| 62dc42b0c5 | |||
| 818aa3c3da | |||
| e12895359b |
@@ -12,6 +12,7 @@
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/error_reporting.ini export-ignore
|
||||
/make-release.sh export-ignore
|
||||
/phpunit.sh export-ignore
|
||||
/phpunit.xml export-ignore
|
||||
|
||||
@@ -6,19 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [3.1.39] - 2021-02-17
|
||||
|
||||
### Security
|
||||
- Prevent access to `$smarty.template_object` in sandbox mode
|
||||
- Fixed code injection vulnerability by using illegal function names in `{function name='blah'}{/function}`
|
||||
|
||||
## [3.1.38] - 2021-01-08
|
||||
|
||||
### Fixed
|
||||
- Smarty::SMARTY_VERSION wasn't updated https://github.com/smarty-php/smarty/issues/628
|
||||
|
||||
## [3.1.37] - 2021-01-07
|
||||
|
||||
### Changed
|
||||
- Changed error handlers and handling of undefined constants for php8-compatibility (set $errcontext argument optional) https://github.com/smarty-php/smarty/issues/605
|
||||
- Changed expected error levels in unit tests for php8-compatibility
|
||||
@@ -27,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
- PHP5.3 compatibility fixes
|
||||
- Brought lexer source functionally up-to-date with compiled version
|
||||
|
||||
## [3.1.36] - 2020-04-14
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Smarty: the PHP compiling template engine
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
|
||||
@@ -249,13 +249,7 @@ template ::= template PHP(B). {
|
||||
|
||||
// template text
|
||||
template ::= template TEXT(B). {
|
||||
$text = $this->yystack[ $this->yyidx + 0 ]->minor;
|
||||
|
||||
if ((string)$text == '') {
|
||||
$this->current_buffer->append_subtree($this, null);
|
||||
}
|
||||
|
||||
$this->current_buffer->append_subtree($this, new Smarty_Internal_ParseTree_Text($text, $this->strip));
|
||||
$this->current_buffer->append_subtree($this, $this->compiler->processText(B));
|
||||
}
|
||||
// strip on
|
||||
template ::= template STRIPON. {
|
||||
@@ -314,7 +308,7 @@ smartytag(A)::= SIMPLETAG(B). {
|
||||
$tag = trim(substr(B, $this->compiler->getLdelLength(), -$this->compiler->getRdelLength()));
|
||||
if ($tag == 'strip') {
|
||||
$this->strip = true;
|
||||
A = null;
|
||||
A = null;;
|
||||
} else {
|
||||
if (defined($tag)) {
|
||||
if ($this->security) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@@ -27,6 +27,7 @@
|
||||
* @author Uwe Tews <uwe dot tews at gmail dot com>
|
||||
* @author Rodney Rehm
|
||||
* @package Smarty
|
||||
* @version 3.1.34-dev
|
||||
*/
|
||||
/**
|
||||
* set SMARTY_DIR to absolute path to Smarty library files.
|
||||
@@ -111,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.39';
|
||||
const SMARTY_VERSION = '3.1.36';
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
|
||||
@@ -58,11 +58,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
}
|
||||
unset($_attr[ 'nocache' ]);
|
||||
$_name = trim($_attr[ 'name' ], '\'"');
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9_\x80-\xff]+$/', $_name)) {
|
||||
$compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
|
||||
}
|
||||
|
||||
$compiler->parent_compiler->tpl_function[ $_name ] = array();
|
||||
$save = array(
|
||||
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||
|
||||
@@ -81,10 +81,6 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
case 'template':
|
||||
return 'basename($_smarty_tpl->source->filepath)';
|
||||
case 'template_object':
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$compiler->trigger_template_error("(secure mode) template_object not permitted");
|
||||
break;
|
||||
}
|
||||
return '$_smarty_tpl';
|
||||
case 'current_dir':
|
||||
return 'dirname($_smarty_tpl->source->filepath)';
|
||||
@@ -98,9 +94,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
break;
|
||||
}
|
||||
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
|
||||
return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)";
|
||||
return "defined('{$_index[1]}') ? constant('{$_index[1]}') : null";
|
||||
} else {
|
||||
return "(defined({$_index[1]}) ? constant({$_index[1]}) : null)";
|
||||
return "defined({$_index[1]}) ? constant({$_index[1]}) : null";
|
||||
}
|
||||
// no break
|
||||
case 'config':
|
||||
|
||||
@@ -115,7 +115,7 @@ class Smarty_Internal_Config_File_Compiler
|
||||
$this->smarty->_debug->start_compile($this->template);
|
||||
}
|
||||
// init the lexer/parser to compile the config file
|
||||
/* @var Smarty_Internal_ConfigFileLexer $this->lex */
|
||||
/* @var Smarty_Internal_ConfigFileLexer $this ->lex */
|
||||
$this->lex = new $this->lexer_class(
|
||||
str_replace(
|
||||
array(
|
||||
@@ -127,7 +127,7 @@ class Smarty_Internal_Config_File_Compiler
|
||||
) . "\n",
|
||||
$this
|
||||
);
|
||||
/* @var Smarty_Internal_ConfigFileParser $this->parser */
|
||||
/* @var Smarty_Internal_ConfigFileParser $this ->parser */
|
||||
$this->parser = new $this->parser_class($this->lex, $this);
|
||||
if (function_exists('mb_internal_encoding')
|
||||
&& function_exists('ini_get')
|
||||
|
||||
@@ -37,8 +37,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
$source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir :
|
||||
$source->smarty->_joined_template_dir)
|
||||
);
|
||||
// When not doing compile_check, set timestamp to true
|
||||
$source->timestamp = $source->smarty->compile_check ? filemtime($source->filepath) : true;
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
} else {
|
||||
$source->timestamp = $source->exists = false;
|
||||
}
|
||||
@@ -51,10 +50,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
if (!$source->smarty->compile_check) {
|
||||
$source->timestamp = $source->exists = true;
|
||||
return;
|
||||
}
|
||||
if (!$source->exists) {
|
||||
$source->timestamp = $source->exists = is_file($source->filepath);
|
||||
}
|
||||
@@ -73,15 +68,13 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if (($source->smarty->compile_check && !$source->exists)
|
||||
|| false === ($content = file_get_contents($source->filepath))
|
||||
) {
|
||||
throw new SmartyException(
|
||||
'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
|
||||
" {$source->type} '{$source->name}'"
|
||||
);
|
||||
if ($source->exists) {
|
||||
return file_get_contents($source->filepath);
|
||||
}
|
||||
return $content;
|
||||
throw new SmartyException(
|
||||
'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
|
||||
" {$source->type} '{$source->name}'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,17 +126,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
$file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file);
|
||||
}
|
||||
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
||||
|
||||
// If possible, assume the file exists when compile_check = false;
|
||||
if (!$source->smarty->compile_check
|
||||
&& count($_directories) == 1 // if there are multiple directories, we'll have to scan them
|
||||
&& $file[ 0 ] !== '[' // template_dir index
|
||||
&& !$source->smarty->use_include_path // cannot optimize when we need to use include path
|
||||
) {
|
||||
$path = reset($_directories) . $file;
|
||||
return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
}
|
||||
|
||||
// template_dir index?
|
||||
if ($file[ 0 ] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
|
||||
$file = $fileMatch[ 2 ];
|
||||
@@ -175,7 +157,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
$_directories = $_index_dirs;
|
||||
}
|
||||
}
|
||||
|
||||
// relative file name?
|
||||
foreach ($_directories as $_directory) {
|
||||
$path = $_directory . $file;
|
||||
|
||||
@@ -74,14 +74,9 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
$this->filepath .= '.cache';
|
||||
}
|
||||
$this->filepath .= '.php';
|
||||
|
||||
if ($smarty->compile_check) {
|
||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||
if ($this->exists) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
}
|
||||
} else {
|
||||
$this->timestamp = $this->exists = true;
|
||||
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||
if ($this->exists) {
|
||||
$this->timestamp = filemtime($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +135,8 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
if ($source->handler->recompiled) {
|
||||
$source->handler->process($_smarty_tpl);
|
||||
} elseif (!$source->handler->uncompiled) {
|
||||
if (
|
||||
$smarty->force_compile ||
|
||||
($_smarty_tpl->compile_check && (!$this->exists || ($source->getTimeStamp() > $this->getTimeStamp())))
|
||||
if (!$this->exists || $smarty->force_compile
|
||||
|| ($_smarty_tpl->compile_check && $source->getTimeStamp() > $this->getTimeStamp())
|
||||
) {
|
||||
$this->compileTemplateSource($_smarty_tpl);
|
||||
$compileCheck = $_smarty_tpl->compile_check;
|
||||
|
||||
+1
-1
@@ -14,6 +14,6 @@ git pull
|
||||
git merge --no-ff "release/$1"
|
||||
git branch -d "release/$1"
|
||||
git tag -a "v$1" -m "Release $1"
|
||||
git push --follow-tags
|
||||
|
||||
printf 'Done creating release %s\n' "$1"
|
||||
printf 'Run `git push --follow-tags origin` to publish it.\n'
|
||||
|
||||
@@ -339,10 +339,6 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
|
||||
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
|
||||
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group slow
|
||||
*/
|
||||
public function testClearCacheExpired()
|
||||
{
|
||||
$this->smarty->caching = true;
|
||||
@@ -403,7 +399,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @dataProvider data
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCache($lockTime, $lockTimeout, $compile_id, $cache_id, $isCached, $tmin, $tmax, $forceCompile, $forceCache, $update, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
|
||||
{
|
||||
|
||||
@@ -125,7 +125,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
* test grandchild/child/parent dependency test2
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_2()
|
||||
{
|
||||
@@ -193,7 +193,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
|
||||
* test grandchild/child/parent dependency test4
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_4()
|
||||
{
|
||||
|
||||
@@ -382,15 +382,6 @@ class SecurityTest extends PHPUnit_Smarty
|
||||
$this->smarty->security_policy->trusted_uri = array();
|
||||
$this->assertContains('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* In security mode, accessing $smarty.template_object should be illegal.
|
||||
* @expectedException SmartyCompilerException
|
||||
*/
|
||||
public function testSmartyTemplateObject() {
|
||||
$this->smarty->display('string:{$smarty.template_object}');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class mysecuritystaticclass
|
||||
|
||||
@@ -610,7 +610,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_2()
|
||||
{
|
||||
@@ -645,7 +645,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_3()
|
||||
{
|
||||
@@ -670,7 +670,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_32()
|
||||
{
|
||||
@@ -692,7 +692,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_4()
|
||||
{
|
||||
@@ -717,7 +716,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*/
|
||||
public function testCompileBlockGrandChildMustCompile_021_42()
|
||||
{
|
||||
|
||||
@@ -210,7 +210,6 @@ class CompileInsertTest extends PHPUnit_Smarty
|
||||
* test insert plugin caching 2
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @group slow
|
||||
*/
|
||||
public function testInsertPluginCaching3_2()
|
||||
{
|
||||
|
||||
@@ -431,14 +431,5 @@ class CompileFunctionTest extends PHPUnit_Smarty
|
||||
array("{function name=simple}A{\$foo}\nC{/function}{call name='simple'}", "Abar\nC", 'T14', $i++),
|
||||
array("{function name=simple}A\n{\$foo}\nC{/function}{call name='simple'}", "A\nbar\nC", 'T15', $i++),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test handling of function names that are a security risk
|
||||
* @expectedException SmartyCompilerException
|
||||
*/
|
||||
public function testIllegalFunctionName() {
|
||||
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class SmartyNowTest extends PHPUnit_Smarty
|
||||
}
|
||||
/**
|
||||
* test {$smarty.now nocache}
|
||||
* @group slow
|
||||
*
|
||||
*/
|
||||
public function testSmartyNowNocache() {
|
||||
$this->smarty->setCaching(true);
|
||||
|
||||
@@ -59,7 +59,7 @@ class StreamVariableTest extends PHPUnit_Smarty
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* test no existent stream variable
|
||||
* test no existant stream variable
|
||||
*/
|
||||
// public function testStreamVariable2()
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user