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 | |
|---|---|---|---|
| 9e443fdacd | |||
| 3e82c271d4 | |||
| dad8005b64 | |||
| dee0c3ffd4 | |||
| 044647bd71 | |||
| c02e9e135e | |||
| 67ab8f6879 | |||
| 773b3b4b7c | |||
| 613c5d691c | |||
| c016895166 |
@@ -31,6 +31,7 @@ jobs:
|
||||
- "7.4"
|
||||
- "8.0"
|
||||
- "8.1"
|
||||
- "8.2"
|
||||
|
||||
compiler:
|
||||
- default
|
||||
@@ -42,6 +43,9 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.1"
|
||||
compiler: jit
|
||||
- os: ubuntu-latest
|
||||
php-version: "8.2"
|
||||
compiler: jit
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
||||
+14
-2
@@ -6,11 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- `$smarty->muteUndefinedOrNullWarnings()` now also mutes PHP7 notices for undefined array indexes [#736](https://github.com/smarty-php/smarty/issues/736)
|
||||
- `$smarty->muteUndefinedOrNullWarnings()` now treats undefined vars and array access of a null or false variables
|
||||
equivalent across all supported PHP versions
|
||||
|
||||
## [4.3.0] - 2022-11-22
|
||||
|
||||
### Added
|
||||
- PHP8.2 compatibility [#775](https://github.com/smarty-php/smarty/pull/775)
|
||||
|
||||
### Changed
|
||||
- Include docs and demo in the releases [#799](https://github.com/smarty-php/smarty/issues/799)
|
||||
- Using PHP functions as modifiers now triggers a deprecation notice because we will drop support for this in the next major release [#813](https://github.com/smarty-php/smarty/issues/813)
|
||||
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)
|
||||
|
||||
- Dropped remaining references to removed PHP-support in Smarty 4 from docs, lexer and security class. [#816](https://github.com/smarty-php/smarty/issues/816)
|
||||
- Support umask when writing (template) files and set dir permissions to 777 [#548](https://github.com/smarty-php/smarty/issues/548) [#819](https://github.com/smarty-php/smarty/issues/819)
|
||||
|
||||
### Fixed
|
||||
- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514)
|
||||
- Fixed recursion and out of memory errors when caching in complicated template set-ups using inheritance and includes [#801](https://github.com/smarty-php/smarty/pull/801)
|
||||
@@ -21,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Adapt Smarty upper/lower functions to be codesafe (e.g. for Turkish locale) [#586](https://github.com/smarty-php/smarty/pull/586)
|
||||
- Bug fix for underscore and limited length in template name in custom resources [#581](https://github.com/smarty-php/smarty/pull/581)
|
||||
|
||||
|
||||
## [4.2.1] - 2022-09-14
|
||||
|
||||
### Security
|
||||
|
||||
@@ -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.1.
|
||||
Smarty can be run with PHP 7.1 to PHP 8.2.
|
||||
|
||||
## Installation
|
||||
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
||||
|
||||
@@ -38,3 +38,8 @@ services:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php81/Dockerfile
|
||||
php82:
|
||||
extends:
|
||||
service: base
|
||||
build:
|
||||
dockerfile: ./utilities/testrunners/php82/Dockerfile
|
||||
|
||||
@@ -2,7 +2,7 @@ What is Smarty?
|
||||
==============
|
||||
|
||||
## Requirements
|
||||
Smarty can be run with PHP 7.1 to PHP 8.1.
|
||||
Smarty can be run with PHP 7.1 to PHP 8.2.
|
||||
|
||||
## Installation
|
||||
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
||||
|
||||
@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '4.2.1';
|
||||
const SMARTY_VERSION = '4.3.0';
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
@@ -1386,8 +1386,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates PHP7 compatibility mode:
|
||||
* - converts E_WARNINGS for "undefined array key" and "trying to read property of null" errors to E_NOTICE
|
||||
* Mutes errors for "undefined index", "undefined array key" and "trying to read property of null".
|
||||
*
|
||||
* @void
|
||||
*/
|
||||
@@ -1396,7 +1395,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if PHP7 compatibility mode is set.
|
||||
* Indicates if Smarty will mute errors for "undefined index", "undefined array key" and "trying to read property of null".
|
||||
* @bool
|
||||
*/
|
||||
public function isMutingUndefinedOrNullWarnings(): bool {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
|
||||
{
|
||||
static $_double_encode = true;
|
||||
static $is_loaded_1 = false;
|
||||
static $is_loaded_2 = false;
|
||||
if (!$char_set) {
|
||||
@@ -34,87 +33,15 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
if ($_double_encode) {
|
||||
// php >=5.3.2 - go native
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
// php <5.2.3 - prevent double encoding
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
// no break
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
// mb_convert_encoding ignores htmlspecialchars()
|
||||
if ($_double_encode) {
|
||||
// php >=5.3.2 - go native
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
// php <5.2.3 - prevent double encoding
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string =
|
||||
str_replace(
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
// htmlentities() won't convert everything, so use mb_convert_encoding
|
||||
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
|
||||
$string = mb_convert_encoding($string, 'UTF-8', $char_set);
|
||||
return htmlentities($string, ENT_QUOTES, 'UTF-8', $double_encode);
|
||||
}
|
||||
// no MBString fallback
|
||||
if ($_double_encode) {
|
||||
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
return htmlentities($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlentities($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(
|
||||
array(
|
||||
'%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'
|
||||
),
|
||||
array(
|
||||
'&',
|
||||
';'
|
||||
),
|
||||
$string
|
||||
);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
// no break
|
||||
case 'url':
|
||||
return rawurlencode($string);
|
||||
|
||||
@@ -18,12 +18,10 @@
|
||||
* @param Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*
|
||||
* @return string with compiled code
|
||||
* @throws \SmartyException
|
||||
* @throws SmartyException
|
||||
*/
|
||||
function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
static $_double_encode = true;
|
||||
static $is_loaded = false;
|
||||
$compiler->template->_checkPlugins(
|
||||
array(
|
||||
array(
|
||||
@@ -41,41 +39,18 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
||||
}
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
if ($_double_encode) {
|
||||
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||
var_export($double_encode, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||
var_export($double_encode, true) . ')';
|
||||
// no break
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if ($_double_encode) {
|
||||
// php >=5.2.3 - go native
|
||||
return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
||||
var_export($char_set, true) . ', ' . var_export($double_encode, true) .
|
||||
'), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
||||
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
return 'htmlentities(mb_convert_encoding((string)' . $params[ 0 ] . ', \'UTF-8\', ' .
|
||||
var_export($char_set, true) . '), ENT_QUOTES, \'UTF-8\', ' .
|
||||
var_export($double_encode, true) . ')';
|
||||
}
|
||||
// no MBString fallback
|
||||
if ($_double_encode) {
|
||||
// php >=5.2.3 - go native
|
||||
return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||
var_export($double_encode, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||
var_export($double_encode, true) . ')';
|
||||
// no break
|
||||
case 'url':
|
||||
return 'rawurlencode((string)' . $params[ 0 ] . ')';
|
||||
|
||||
@@ -39,9 +39,9 @@ function smarty_modifiercompiler_unescape($params, Smarty_Internal_TemplateCompi
|
||||
case 'entity':
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
|
||||
return 'html_entity_decode(mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'UTF-8\'), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' . $params[ 2 ] . ')';
|
||||
}
|
||||
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
|
||||
return 'html_entity_decode(' . $params[ 0 ] . ', ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' . $params[ 2 ] . ')';
|
||||
case 'html':
|
||||
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
|
||||
case 'url':
|
||||
|
||||
@@ -66,12 +66,16 @@ class Smarty_Internal_ErrorHandler
|
||||
*/
|
||||
public function handleError($errno, $errstr, $errfile, $errline, $errcontext = [])
|
||||
{
|
||||
if ($this->allowUndefinedVars && $errstr == 'Attempt to read property "value" on null') {
|
||||
|
||||
if ($this->allowUndefinedVars && preg_match(
|
||||
'/^(Attempt to read property "value" on null|Trying to get property (\'value\' )?of non-object)/',
|
||||
$errstr
|
||||
)) {
|
||||
return; // suppresses this error
|
||||
}
|
||||
|
||||
if ($this->allowUndefinedArrayKeys && preg_match(
|
||||
'/^(Undefined array key|Trying to access array offset on value of type null)/',
|
||||
'/^(Undefined index|Undefined array key|Trying to access array offset on value of type (null|bool))/',
|
||||
$errstr
|
||||
)) {
|
||||
return; // suppresses this error
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
|
||||
* @property mixed|\Smarty_Template_Cached configLoad
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class Smarty_Internal_Extension_Handler
|
||||
{
|
||||
public $objType = null;
|
||||
|
||||
@@ -22,7 +22,7 @@ class Smarty_Internal_Runtime_Make_Nocache
|
||||
{
|
||||
if (isset($tpl->tpl_vars[ $var ])) {
|
||||
$export =
|
||||
preg_replace('/^Smarty_Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[ $var ], true));
|
||||
preg_replace('/^\\\\?Smarty_Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[ $var ], true));
|
||||
if (preg_match('/(\w+)::__set_state/', $export, $match)) {
|
||||
throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ class Smarty_Internal_Runtime_WriteFile
|
||||
{
|
||||
$_error_reporting = error_reporting();
|
||||
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||
$old_umask = umask(0);
|
||||
$_dirpath = dirname($_filepath);
|
||||
// if subdirs, create dir structure
|
||||
if ($_dirpath !== '.') {
|
||||
@@ -37,7 +36,7 @@ class Smarty_Internal_Runtime_WriteFile
|
||||
// loop if concurrency problem occurs
|
||||
// see https://bugs.php.net/bug.php?id=35326
|
||||
while (!is_dir($_dirpath)) {
|
||||
if (@mkdir($_dirpath, 0771, true)) {
|
||||
if (@mkdir($_dirpath, 0777, true)) {
|
||||
break;
|
||||
}
|
||||
clearstatcache();
|
||||
@@ -85,8 +84,7 @@ class Smarty_Internal_Runtime_WriteFile
|
||||
throw new SmartyException("unable to write file {$_filepath}");
|
||||
}
|
||||
// set file permissions
|
||||
chmod($_filepath, 0644);
|
||||
umask($old_umask);
|
||||
@chmod($_filepath, 0666 & ~umask());
|
||||
error_reporting($_error_reporting);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*
|
||||
* @method bool mustCompile()
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -1131,8 +1131,12 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
echo ob_get_clean();
|
||||
flush();
|
||||
}
|
||||
$e = new SmartyCompilerException($error_text);
|
||||
$e->setLine($line);
|
||||
$e = new SmartyCompilerException(
|
||||
$error_text,
|
||||
0,
|
||||
$this->template->source->filepath,
|
||||
$line
|
||||
);
|
||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
||||
$e->desc = $args;
|
||||
$e->template = $this->template->source->filepath;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
/**
|
||||
* This class does contain the security settings
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class Smarty_Security
|
||||
{
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class Smarty_Variable
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,33 @@
|
||||
*/
|
||||
class SmartyCompilerException extends SmartyException
|
||||
{
|
||||
/**
|
||||
* The constructor of the exception
|
||||
*
|
||||
* @param string $message The Exception message to throw.
|
||||
* @param int $code The Exception code.
|
||||
* @param string|null $filename The filename where the exception is thrown.
|
||||
* @param int|null $line The line number where the exception is thrown.
|
||||
* @param Throwable|null $previous The previous exception used for the exception chaining.
|
||||
*/
|
||||
public function __construct(
|
||||
string $message = "",
|
||||
int $code = 0,
|
||||
?string $filename = null,
|
||||
?int $line = null,
|
||||
Throwable $previous = null
|
||||
) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
// These are optional parameters, should be be overridden only when present!
|
||||
if ($filename) {
|
||||
$this->file = $filename;
|
||||
}
|
||||
if ($line) {
|
||||
$this->line = $line;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -22,6 +49,7 @@ class SmartyCompilerException extends SmartyException
|
||||
{
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* The template source snippet relating to the error
|
||||
*
|
||||
|
||||
@@ -88,14 +88,12 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
||||
}
|
||||
|
||||
public function testUndefinedSimpleVar() {
|
||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||
$this->smarty->muteUndefinedOrNullWarnings();
|
||||
$tpl = $this->smarty->createTemplate('string:a{if $undef}def{/if}b');
|
||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testUndefinedArrayIndex() {
|
||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||
$this->smarty->muteUndefinedOrNullWarnings();
|
||||
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef}def{/if}b');
|
||||
$tpl->assign('ar', []);
|
||||
@@ -103,7 +101,6 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
||||
}
|
||||
|
||||
public function testUndefinedArrayIndexDeep() {
|
||||
$this->smarty->setErrorReporting(E_ALL & ~E_NOTICE);
|
||||
$this->smarty->muteUndefinedOrNullWarnings();
|
||||
$tpl = $this->smarty->createTemplate('string:a{if $ar.undef.nope.neither}def{/if}b');
|
||||
$tpl->assign('ar', []);
|
||||
@@ -133,5 +130,19 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
|
||||
$this->assertTrue($exceptionThrown);
|
||||
}
|
||||
|
||||
public function testUsingNullAsAnArrayIsMuted() {
|
||||
$this->smarty->setErrorReporting(E_ALL);
|
||||
$this->smarty->muteUndefinedOrNullWarnings();
|
||||
$tpl = $this->smarty->createTemplate('string:a{if $undef.k}def{/if}b');
|
||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testUsingFalseAsAnArrayIsMuted() {
|
||||
$this->smarty->setErrorReporting(E_ALL);
|
||||
$this->smarty->muteUndefinedOrNullWarnings();
|
||||
$tpl = $this->smarty->createTemplate('string:a{if $nottrue.k}def{/if}b');
|
||||
$this->smarty->assign('nottrue', false);
|
||||
$this->assertEquals("ab", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ class StreamResourceTest extends PHPUnit_Smarty
|
||||
}
|
||||
}
|
||||
|
||||
#[AllowDynamicProperties]
|
||||
class ResourceStream
|
||||
{
|
||||
private $position;
|
||||
|
||||
@@ -391,6 +391,7 @@ class Security extends Smarty_Security
|
||||
{
|
||||
|
||||
}
|
||||
#[AllowDynamicProperties]
|
||||
class ResourceStreamSecurity
|
||||
{
|
||||
private $position;
|
||||
|
||||
+5
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
class CompileRegisteredObjectFunctionTest extends PHPUnit_Smarty
|
||||
{
|
||||
/**
|
||||
* @var RegObject
|
||||
*/
|
||||
private $object;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
|
||||
+4
-4
@@ -23,7 +23,7 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty
|
||||
public function testToLatin1()
|
||||
{
|
||||
$encoded = "hällö wörld 1";
|
||||
$result = utf8_decode($encoded);
|
||||
$result = mb_convert_encoding($encoded, 'ISO-8859-1', 'UTF-8');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|to_charset}');
|
||||
$this->assertEquals(str_replace("\r", '', $result), $tpl->fetch());
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty
|
||||
Smarty::$_MBSTRING = false;
|
||||
$this->smarty->setCompileId('mb');
|
||||
$encoded = "hällö wörld 2";
|
||||
$result = utf8_decode($encoded);
|
||||
$result = mb_convert_encoding($encoded, 'ISO-8859-1', 'UTF-8');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|to_charset}');
|
||||
$this->assertEquals($encoded, $tpl->fetch());
|
||||
Smarty::$_MBSTRING = true;
|
||||
@@ -42,7 +42,7 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty
|
||||
public function testFromLatin1()
|
||||
{
|
||||
$result = "hällö wörld 3";
|
||||
$encoded = utf8_decode($result);
|
||||
$encoded = mb_convert_encoding($result, 'ISO-8859-1', 'UTF-8');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|from_charset}');
|
||||
$this->assertEquals(str_replace("\r", '', $result), $tpl->fetch());
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class PluginModifierCharsetTest extends PHPUnit_Smarty
|
||||
Smarty::$_MBSTRING = false;
|
||||
$this->smarty->setCompileId('mb');
|
||||
$result = "hällö wörld 4";
|
||||
$encoded = utf8_decode($result);
|
||||
$encoded = mb_convert_encoding($result, 'ISO-8859-1', 'UTF-8');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|from_charset}');
|
||||
$this->assertEquals($encoded, $tpl->fetch());
|
||||
Smarty::$_MBSTRING = true;
|
||||
|
||||
+35
-5
@@ -20,12 +20,19 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
||||
$this->setUpSmarty(__DIR__);
|
||||
}
|
||||
|
||||
public function testHtml()
|
||||
public function testHtmlCompiled()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"html"}');
|
||||
$this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testHtmlModifier()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:$mode}');
|
||||
$this->smarty->assign('mode', 'html');
|
||||
$this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testHtmlWithoutMbstring()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
@@ -48,13 +55,20 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
||||
Smarty::$_MBSTRING = true;
|
||||
}
|
||||
|
||||
public function testHtmlall()
|
||||
public function testHtmlallCompiled()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall"}');
|
||||
$this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testHtmlallWithoutMbstring()
|
||||
public function testHtmlallModifier()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:$mode}');
|
||||
$this->smarty->assign('mode', 'htmlall');
|
||||
$this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testHtmlallWithoutMbstringCompiled()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall"}');
|
||||
@@ -62,6 +76,15 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
||||
Smarty::$_MBSTRING = true;
|
||||
}
|
||||
|
||||
public function testHtmlallWithoutMbstringModifier()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:$mode}');
|
||||
$this->smarty->assign('mode', 'htmlall');
|
||||
$this->assertEquals("I'm some <html> to ä be "escaped" or &copy;", $this->smarty->fetch($tpl));
|
||||
Smarty::$_MBSTRING = true;
|
||||
}
|
||||
|
||||
public function testHtmlallDouble()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"I\'m some <html> to ä be \"escaped\" or ©"|escape:"htmlall":null:false}');
|
||||
@@ -76,12 +99,19 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
||||
Smarty::$_MBSTRING = true;
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
public function testUrlCompiled()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:"url"}');
|
||||
$this->assertEquals("http%3A%2F%2Fsome.encoded.com%2Furl%3Fparts%23foo", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testUrlModifier()
|
||||
{
|
||||
$tpl = $this->smarty->createTemplate('string:{"http://some.encoded.com/url?parts#foo"|escape:$mode}');
|
||||
$this->smarty->assign('mode', 'url');
|
||||
$this->assertEquals("http%3A%2F%2Fsome.encoded.com%2Furl%3Fparts%23foo", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testUrlWithoutMbstring()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
@@ -203,7 +233,7 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
||||
public function testNonstdWithoutMbstring()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . utf8_decode('sma\'rty@»example«.com') . '"|escape:"nonstd"}');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . mb_convert_encoding('sma\'rty@»example«.com', 'ISO-8859-1', 'UTF-8') . '"|escape:"nonstd"}');
|
||||
$this->assertEquals("sma'rty@»example«.com", $this->smarty->fetch($tpl));
|
||||
Smarty::$_MBSTRING = true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class PluginModifierStripTest extends PHPUnit_Smarty
|
||||
{
|
||||
// Some Unicode Spaces
|
||||
$string = " hello spaced       words ";
|
||||
$string = mb_convert_encoding($string, 'UTF-8', "HTML-ENTITIES");
|
||||
$string = html_entity_decode($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $string . '"|strip}');
|
||||
$this->assertEquals(" hello spaced words ", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
+4
-4
@@ -40,8 +40,8 @@ class PluginModifierUnescapeTest extends PHPUnit_Smarty
|
||||
|
||||
public function testHtmlall()
|
||||
{
|
||||
$encoded = "aäЗдра><&amp;ääвсствуйте";
|
||||
$result = "aäЗдра><&ääвсствуйте";
|
||||
$encoded = "'"aäЗдра><&amp;ääвсствуйте";
|
||||
$result = "'\"aäЗдра><&ääвсствуйте";
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|unescape:"htmlall"}');
|
||||
$this->assertEquals($result, $this->smarty->fetch($tpl));
|
||||
}
|
||||
@@ -49,8 +49,8 @@ class PluginModifierUnescapeTest extends PHPUnit_Smarty
|
||||
public function testHtmlallWithoutMbstring()
|
||||
{
|
||||
Smarty::$_MBSTRING = false;$this->smarty->setCompileId('mb');
|
||||
$encoded = "aäЗдра><&amp;ääвсствуйте";
|
||||
$result = "aäЗдра><&ääвсствуйте";
|
||||
$encoded = "'"aäЗдра><&amp;ääвсствуйте";
|
||||
$result = "'\"aäЗдра><&ääвсствуйте";
|
||||
$tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|unescape:"htmlall"}');
|
||||
$this->assertEquals($result, $this->smarty->fetch($tpl));
|
||||
Smarty::$_MBSTRING = true;
|
||||
|
||||
@@ -68,6 +68,7 @@ class StreamVariableTest extends PHPUnit_Smarty
|
||||
// }
|
||||
}
|
||||
|
||||
#[AllowDynamicProperties]
|
||||
class VariableStream
|
||||
{
|
||||
private $position;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
FROM php:8.2-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
|
||||
Reference in New Issue
Block a user