mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-10 07:21:31 +02:00
Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb95216671 | ||
|
|
d6ac3297df | ||
|
|
560475a2f2 | ||
|
|
382d66305d | ||
|
|
44bac8d58c | ||
|
|
f8e1ba76f7 | ||
|
|
629504485f | ||
|
|
71036be8be | ||
|
|
78f0cf5f65 | ||
|
|
64ad6442ca | ||
|
|
7eff7d6fb0 | ||
|
|
05f1a7deda | ||
|
|
3f97b7352e | ||
|
|
a6711b3833 | ||
|
|
52056ce65a | ||
|
|
8b96efad45 | ||
|
|
bfa02f3b91 | ||
|
|
89dc506638 | ||
|
|
e68065bc33 | ||
|
|
db2547287c | ||
|
|
962f266483 | ||
|
|
8aeb5d6821 | ||
|
|
a2e1df1768 | ||
|
|
fe6d333c60 | ||
|
|
50c4604857 | ||
|
|
e5a6ff42f8 | ||
|
|
3cc56392c6 | ||
|
|
17025423e1 | ||
|
|
18d3e564da | ||
|
|
0d2c38b482 | ||
|
|
f90348971b | ||
|
|
9e0536de18 | ||
|
|
265cf4f3bc | ||
|
|
47f95ad324 | ||
|
|
02633ecaba | ||
|
|
6786623afb | ||
|
|
2d97169086 | ||
|
|
0f098802c6 | ||
|
|
bbcd5817f6 | ||
|
|
612094d763 | ||
|
|
0ef0dda825 | ||
|
|
cef8951100 | ||
|
|
323aefa89f | ||
|
|
277648b81c | ||
|
|
8d3a7af308 | ||
|
|
cdf0f2b164 | ||
|
|
995b7eb36f | ||
|
|
059bea274c | ||
|
|
f707dadecb | ||
|
|
ace1c8e90f | ||
|
|
19ae410bf5 | ||
|
|
baad3115cd | ||
|
|
dff1955cd5 |
+5
-2
@@ -7,8 +7,11 @@
|
|||||||
|
|
||||||
# exclude from git export
|
# exclude from git export
|
||||||
/tests export-ignore
|
/tests export-ignore
|
||||||
/utilities/ export-ignore
|
/demo export-ignore
|
||||||
|
/docs export-ignore
|
||||||
|
/utilities export-ignore
|
||||||
|
/docker-compose.yml export-ignore
|
||||||
|
/.github export-ignore
|
||||||
/.gitattributes export-ignore
|
/.gitattributes export-ignore
|
||||||
/.gitignore export-ignore
|
/.gitignore export-ignore
|
||||||
/make-release.sh export-ignore
|
/make-release.sh export-ignore
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ jobs:
|
|||||||
- "7.3"
|
- "7.3"
|
||||||
- "7.4"
|
- "7.4"
|
||||||
- "8.0"
|
- "8.0"
|
||||||
|
- "8.1"
|
||||||
|
|
||||||
compiler:
|
compiler:
|
||||||
- default
|
- default
|
||||||
@@ -36,6 +37,9 @@ jobs:
|
|||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
php-version: "8.0"
|
php-version: "8.0"
|
||||||
compiler: jit
|
compiler: jit
|
||||||
|
- os: ubuntu-latest
|
||||||
|
php-version: "8.1"
|
||||||
|
compiler: jit
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
lexer/*.php
|
lexer/*.php
|
||||||
lexer/*.php.bak
|
lexer/*.php.bak
|
||||||
lexer/*.out
|
lexer/*.out
|
||||||
utilies/*.php
|
|
||||||
|
|
||||||
# Dev
|
# Dev
|
||||||
phpunit*
|
phpunit*
|
||||||
|
|||||||
@@ -6,6 +6,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Updated HTML of the debug template [#599](https://github.com/smarty-php/smarty/pull/599)
|
||||||
|
|
||||||
|
## [4.1.1] - 2022-05-17
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent PHP injection through malicious block name or include file name. This addresses CVE-2022-29221
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Exclude docs and demo from export and composer [#751](https://github.com/smarty-php/smarty/pull/751)
|
||||||
|
- PHP 8.1 deprecation notices in demo/plugins/cacheresource.pdo.php [#706](https://github.com/smarty-php/smarty/issues/706)
|
||||||
|
- PHP 8.1 deprecation notices in truncate modifier [#699](https://github.com/smarty-php/smarty/issues/699)
|
||||||
|
- Math equation `max(x, y)` didn't work anymore [#721](https://github.com/smarty-php/smarty/issues/721)
|
||||||
|
- Fix PHP 8.1 deprecated warning when calling rtrim [#743](https://github.com/smarty-php/smarty/pull/743)
|
||||||
|
- PHP 8.1: fix deprecation in escape modifier [#727](https://github.com/smarty-php/smarty/pull/727)
|
||||||
|
|
||||||
|
## [4.1.0] - 2022-02-06
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- PHP8.1 compatibility [#713](https://github.com/smarty-php/smarty/pull/713)
|
||||||
|
|
||||||
|
## [4.0.4] - 2022-01-18
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Fixed illegal characters bug in math function security check [#702](https://github.com/smarty-php/smarty/issues/702)
|
||||||
|
|
||||||
|
## [4.0.3] - 2022-01-10
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Prevent evasion of the `static_classes` security policy. This addresses CVE-2021-21408
|
||||||
|
|
||||||
## [4.0.2] - 2022-01-10
|
## [4.0.2] - 2022-01-10
|
||||||
|
|
||||||
### Security
|
### 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.
|
Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it.
|
||||||
|
|
||||||
## Requirements
|
## 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
|
## Installation
|
||||||
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
* @return void
|
* @return void
|
||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
protected function fetch($id, $name, $cache_id = null, $compile_id = null, &$content, &$mtime)
|
protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
|
||||||
{
|
{
|
||||||
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
$stmt = $this->getFetchStatement($this->fetchColumns, $id, $cache_id, $compile_id);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
@@ -244,7 +244,7 @@ class Smarty_CacheResource_Pdo extends Smarty_CacheResource_Custom
|
|||||||
* @return boolean success
|
* @return boolean success
|
||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
protected function save($id, $name, $cache_id = null, $compile_id = null, $exp_time, $content)
|
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
|
||||||
{
|
{
|
||||||
$stmt = $this->pdo->prepare($this->insertStatement);
|
$stmt = $this->pdo->prepare($this->insertStatement);
|
||||||
$stmt->bindValue('id', $id);
|
$stmt->bindValue('id', $id);
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
version: "2"
|
||||||
|
services:
|
||||||
|
base:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
working_dir: /app
|
||||||
|
entrypoint: sh ./utilities/testrunners/run-test.sh
|
||||||
|
php71:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php71/Dockerfile
|
||||||
|
php72:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php72/Dockerfile
|
||||||
|
php73:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php73/Dockerfile
|
||||||
|
php74:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php74/Dockerfile
|
||||||
|
php80:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php80/Dockerfile
|
||||||
|
php81:
|
||||||
|
extends:
|
||||||
|
service: base
|
||||||
|
build:
|
||||||
|
dockerfile: ./utilities/testrunners/php81/Dockerfile
|
||||||
@@ -2,7 +2,7 @@ What is Smarty?
|
|||||||
==============
|
==============
|
||||||
|
|
||||||
## Requirements
|
## 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
|
## Installation
|
||||||
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Setting `$escape_html` to TRUE will escape all template variable output
|
Setting `$escape_html` to TRUE will escape all template variable output
|
||||||
by wrapping it in
|
by wrapping it in
|
||||||
`htmlspecialchars({$output}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET);`,
|
`htmlspecialchars({$output}, ENT_QUOTES, $char_set);`,
|
||||||
which is the same as `{$variable|escape:"html"}`.
|
which is the same as `{$variable|escape:"html"}`.
|
||||||
|
|
||||||
Template designers can choose to selectively disable this feature by
|
Template designers can choose to selectively disable this feature by
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ Charset Encoding {#charset.encoding}
|
|||||||
================
|
================
|
||||||
|
|
||||||
There are a variety of encodings for textual data, ISO-8859-1 (Latin1)
|
There are a variety of encodings for textual data, ISO-8859-1 (Latin1)
|
||||||
and UTF-8 being the most popular. Unless specified otherwise with the
|
and UTF-8 being the most popular. Unless you change `Smarty::$_CHARSET`,
|
||||||
`SMARTY_RESOURCE_CHAR_SET` constant, Smarty recognizes `UTF-8` as the
|
Smarty recognizes `UTF-8` as the internal charset if
|
||||||
internal charset if [Multibyte String](https://www.php.net/mbstring) is
|
[Multibyte String](https://www.php.net/mbstring) is available,
|
||||||
available, `ISO-8859-1` if not.
|
`ISO-8859-1` if not.
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
@@ -36,8 +36,9 @@ available, `ISO-8859-1` if not.
|
|||||||
if (function_exists('mb_internal_charset')) {
|
if (function_exists('mb_internal_charset')) {
|
||||||
mb_internal_charset('EUC-JP');
|
mb_internal_charset('EUC-JP');
|
||||||
}
|
}
|
||||||
define('SMARTY_RESOURCE_CHAR_SET', 'EUC-JP');
|
|
||||||
require_once 'libs/Smarty.class.php';
|
require_once 'libs/Smarty.class.php';
|
||||||
|
Smarty::$_CHARSET = 'EUC-JP';
|
||||||
$smarty = new Smarty();
|
$smarty = new Smarty();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -747,6 +747,9 @@ value(res) ::= doublequoted_with_quotes(s). {
|
|||||||
|
|
||||||
|
|
||||||
value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
||||||
|
if ($this->security && $this->security->static_classes !== array()) {
|
||||||
|
$this->compiler->trigger_template_error('dynamic static class not allowed by security setting');
|
||||||
|
}
|
||||||
$prefixVar = $this->compiler->getNewPrefixVariable();
|
$prefixVar = $this->compiler->getNewPrefixVariable();
|
||||||
if (vi['var'] === '\'smarty\'') {
|
if (vi['var'] === '\'smarty\'') {
|
||||||
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>');
|
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>');
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '4.0.2';
|
const SMARTY_VERSION = '4.1.1';
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
*/
|
*/
|
||||||
@@ -867,7 +867,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
$this->plugins_dir = (array)$this->plugins_dir;
|
$this->plugins_dir = (array)$this->plugins_dir;
|
||||||
}
|
}
|
||||||
foreach ($this->plugins_dir as $k => $v) {
|
foreach ($this->plugins_dir as $k => $v) {
|
||||||
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true);
|
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v ?? '', '/\\') . DIRECTORY_SEPARATOR, true);
|
||||||
}
|
}
|
||||||
$this->_cache[ 'plugin_files' ] = array();
|
$this->_cache[ 'plugin_files' ] = array();
|
||||||
$this->_pluginsDirNormalized = true;
|
$this->_pluginsDirNormalized = true;
|
||||||
@@ -1345,7 +1345,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
private function _normalizeDir($dirName, $dir)
|
private function _normalizeDir($dirName, $dir)
|
||||||
{
|
{
|
||||||
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true);
|
$this->{$dirName} = $this->_realpath(rtrim($dir ?? '', "/\\") . DIRECTORY_SEPARATOR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1367,7 +1367,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
foreach ($dir as $k => $v) {
|
foreach ($dir as $k => $v) {
|
||||||
if (!isset($processed[ $k ])) {
|
if (!isset($processed[ $k ])) {
|
||||||
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
|
$dir[ $k ] = $v = $this->_realpath(rtrim($v ?? '', "/\\") . DIRECTORY_SEPARATOR, true);
|
||||||
$processed[ $k ] = true;
|
$processed[ $k ] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-19
@@ -1,9 +1,9 @@
|
|||||||
{capture name='_smarty_debug' assign=debug_output}
|
{capture name='_smarty_debug' assign=debug_output}
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
<!DOCTYPE html>
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Smarty Debug Console</title>
|
<title>Smarty Debug Console</title>
|
||||||
<style type="text/css">
|
<style>
|
||||||
{literal}
|
{literal}
|
||||||
body, h1, h2, h3, td, th, p {
|
body, h1, h2, h3, td, th, p {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
padding: 2px;
|
padding: 2px;
|
||||||
border-top: 1px solid black;
|
border-top: 1px solid black;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -67,11 +68,11 @@
|
|||||||
color: green;
|
color: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
.odd {
|
tr:nth-child(odd) {
|
||||||
background-color: #eeeeee;
|
background-color: #eeeeee;
|
||||||
}
|
}
|
||||||
|
|
||||||
.even {
|
tr:nth-child(even) {
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,13 +85,16 @@
|
|||||||
color: black;
|
color: black;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#blue h3 {
|
#blue h3 {
|
||||||
color: blue;
|
color: blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#normal div {
|
#normal div {
|
||||||
color: black;
|
color: black;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
#table_assigned_vars th {
|
#table_assigned_vars th {
|
||||||
color: blue;
|
color: blue;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -99,7 +103,6 @@
|
|||||||
#table_config_vars th {
|
#table_config_vars th {
|
||||||
color: maroon;
|
color: maroon;
|
||||||
}
|
}
|
||||||
|
|
||||||
{/literal}
|
{/literal}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -112,11 +115,11 @@
|
|||||||
<h2>included templates & config files (load time in seconds)</h2>
|
<h2>included templates & config files (load time in seconds)</h2>
|
||||||
<div>
|
<div>
|
||||||
{foreach $template_data as $template}
|
{foreach $template_data as $template}
|
||||||
<font color=brown>{$template.name}</font>
|
<span style="color: brown;">{$template.name}</span>
|
||||||
<br /> <span class="exectime">
|
<br> <span class="exectime">
|
||||||
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
|
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
|
||||||
</span>
|
</span>
|
||||||
<br />
|
<br>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -125,13 +128,22 @@
|
|||||||
|
|
||||||
<table id="table_assigned_vars">
|
<table id="table_assigned_vars">
|
||||||
{foreach $assigned_vars as $vars}
|
{foreach $assigned_vars as $vars}
|
||||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
<tr>
|
||||||
<td><h3><font color=blue>${$vars@key}</font></h3>
|
<td>
|
||||||
{if isset($vars['nocache'])}<b>Nocache</b><br />{/if}
|
<h3 style="color: blue;">${$vars@key}</h3>
|
||||||
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
|
{if isset($vars['nocache'])}<strong>Nocache</strong><br>{/if}
|
||||||
|
{if isset($vars['scope'])}<strong>Origin:</strong> {$vars['scope']|debug_print_var nofilter}{/if}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h3>Value</h3>
|
||||||
|
{$vars['value']|debug_print_var:10:80 nofilter}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{if isset($vars['attributes'])}
|
||||||
|
<h3>Attributes</h3>
|
||||||
|
{$vars['attributes']|debug_print_var nofilter}
|
||||||
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>
|
|
||||||
<td>{if isset($vars['attributes'])}<h3>Attributes</h3>{$vars['attributes']|debug_print_var nofilter} {/if}</td>
|
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -139,11 +151,14 @@
|
|||||||
|
|
||||||
<table id="table_config_vars">
|
<table id="table_config_vars">
|
||||||
{foreach $config_vars as $vars}
|
{foreach $config_vars as $vars}
|
||||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
<tr>
|
||||||
<td><h3><font color=blue>#{$vars@key}#</font></h3>
|
<td>
|
||||||
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
|
<h3 style="color: blue;">#{$vars@key}#</h3>
|
||||||
|
{if isset($vars['scope'])}<strong>Origin:</strong> {$vars['scope']|debug_print_var nofilter}{/if}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{$vars['value']|debug_print_var:10:80 nofilter}
|
||||||
</td>
|
</td>
|
||||||
<td>{$vars['value']|debug_print_var:10:80 nofilter}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
|
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ function smarty_function_math($params, $template)
|
|||||||
// Adapted from https://www.php.net/manual/en/function.eval.php#107377
|
// 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]*))';
|
$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.'(?2))?)+$/';
|
$regexp = '/^(('.$number.'|'.$functionsOrVars.'|('.$functionsOrVars.'\s*\((?1)+\)|\((?1)+\)))(?:'.$operators.'(?1))?)+$/';
|
||||||
|
|
||||||
if (!preg_match($regexp, $equation)) {
|
if (!preg_match($regexp, $equation)) {
|
||||||
trigger_error("math: illegal characters", E_USER_WARNING);
|
trigger_error("math: illegal characters", E_USER_WARNING);
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
|||||||
if (!$char_set) {
|
if (!$char_set) {
|
||||||
$char_set = Smarty::$_CHARSET;
|
$char_set = Smarty::$_CHARSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$string = (string)$string;
|
||||||
|
|
||||||
switch ($esc_type) {
|
switch ($esc_type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
if ($_double_encode) {
|
if ($_double_encode) {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
|
|||||||
if (!$middle) {
|
if (!$middle) {
|
||||||
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
|
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
|
||||||
}
|
}
|
||||||
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
|
return mb_substr($string, 0, intval($length / 2), Smarty::$_CHARSET) . $etc .
|
||||||
mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
|
mb_substr($string, -intval($length / 2), $length, Smarty::$_CHARSET);
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
|
|||||||
if (!$middle) {
|
if (!$middle) {
|
||||||
return substr($string, 0, $length) . $etc;
|
return substr($string, 0, $length) . $etc;
|
||||||
}
|
}
|
||||||
return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
|
return substr($string, 0, intval($length / 2)) . $etc . substr($string, -intval($length / 2));
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
|||||||
switch ($esc_type) {
|
switch ($esc_type) {
|
||||||
case 'html':
|
case 'html':
|
||||||
if ($_double_encode) {
|
if ($_double_encode) {
|
||||||
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||||
var_export($double_encode, true) . ')';
|
var_export($double_encode, true) . ')';
|
||||||
} elseif ($double_encode) {
|
} elseif ($double_encode) {
|
||||||
return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
||||||
} else {
|
} else {
|
||||||
// fall back to modifier.escape.php
|
// fall back to modifier.escape.php
|
||||||
}
|
}
|
||||||
@@ -54,12 +54,12 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
|||||||
if (Smarty::$_MBSTRING) {
|
if (Smarty::$_MBSTRING) {
|
||||||
if ($_double_encode) {
|
if ($_double_encode) {
|
||||||
// php >=5.2.3 - go native
|
// php >=5.2.3 - go native
|
||||||
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
||||||
var_export($char_set, true) . ', ' . var_export($double_encode, true) .
|
var_export($char_set, true) . ', ' . var_export($double_encode, true) .
|
||||||
'), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
'), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
||||||
} elseif ($double_encode) {
|
} elseif ($double_encode) {
|
||||||
// php <5.2.3 - only handle double encoding
|
// php <5.2.3 - only handle double encoding
|
||||||
return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
return 'mb_convert_encoding(htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' .
|
||||||
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
|
||||||
} else {
|
} else {
|
||||||
// fall back to modifier.escape.php
|
// fall back to modifier.escape.php
|
||||||
@@ -68,26 +68,26 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
|||||||
// no MBString fallback
|
// no MBString fallback
|
||||||
if ($_double_encode) {
|
if ($_double_encode) {
|
||||||
// php >=5.2.3 - go native
|
// php >=5.2.3 - go native
|
||||||
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
|
||||||
var_export($double_encode, true) . ')';
|
var_export($double_encode, true) . ')';
|
||||||
} elseif ($double_encode) {
|
} elseif ($double_encode) {
|
||||||
// php <5.2.3 - only handle double encoding
|
// php <5.2.3 - only handle double encoding
|
||||||
return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
return 'htmlentities((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
|
||||||
} else {
|
} else {
|
||||||
// fall back to modifier.escape.php
|
// fall back to modifier.escape.php
|
||||||
}
|
}
|
||||||
// no break
|
// no break
|
||||||
case 'url':
|
case 'url':
|
||||||
return 'rawurlencode(' . $params[ 0 ] . ')';
|
return 'rawurlencode((string)' . $params[ 0 ] . ')';
|
||||||
case 'urlpathinfo':
|
case 'urlpathinfo':
|
||||||
return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
|
return 'str_replace("%2F", "/", rawurlencode((string)' . $params[ 0 ] . '))';
|
||||||
case 'quotes':
|
case 'quotes':
|
||||||
// escape unescaped single quotes
|
// escape unescaped single quotes
|
||||||
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[ 0 ] . ')';
|
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'", (string)' . $params[ 0 ] . ')';
|
||||||
case 'javascript':
|
case 'javascript':
|
||||||
// escape quotes and backslashes, newlines, etc.
|
// escape quotes and backslashes, newlines, etc.
|
||||||
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
||||||
return 'strtr(' .
|
return 'strtr((string)' .
|
||||||
$params[ 0 ] .
|
$params[ 0 ] .
|
||||||
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
|
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,8 +196,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
|||||||
*/
|
*/
|
||||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||||
{
|
{
|
||||||
clearstatcache(true, $cached->lock_id);
|
clearstatcache(true, $cached->lock_id ?? '');
|
||||||
if (is_file($cached->lock_id)) {
|
if (null !== $cached->lock_id && is_file($cached->lock_id)) {
|
||||||
$t = filemtime($cached->lock_id);
|
$t = filemtime($cached->lock_id);
|
||||||
return $t && (time() - $t < $smarty->locking_timeout);
|
return $t && (time() - $t < $smarty->locking_timeout);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
|
|||||||
// setup buffer for template function code
|
// setup buffer for template function code
|
||||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {block {$_name}} */\n";
|
$output .= $compiler->cStyleComment(" {block {$_name}} ") . "\n";
|
||||||
$output .= "class {$_className} extends Smarty_Internal_Block\n";
|
$output .= "class {$_className} extends Smarty_Internal_Block\n";
|
||||||
$output .= "{\n";
|
$output .= "{\n";
|
||||||
foreach ($_block as $property => $value) {
|
foreach ($_block as $property => $value) {
|
||||||
@@ -155,7 +155,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
|
|||||||
}
|
}
|
||||||
$output .= "}\n";
|
$output .= "}\n";
|
||||||
$output .= "}\n";
|
$output .= "}\n";
|
||||||
$output .= "/* {/block {$_name}} */\n\n";
|
$output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n";
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$compiler->parser->current_buffer->append_subtree(
|
$compiler->parser->current_buffer->append_subtree(
|
||||||
$compiler->parser,
|
$compiler->parser,
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
if ($compiler->template->compiled->has_nocache_code) {
|
if ($compiler->template->compiled->has_nocache_code) {
|
||||||
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching;
|
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcNameCaching} */\n";
|
$output .= $compiler->cStyleComment(" {$_funcNameCaching} ") . "\n";
|
||||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||||
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
|
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
|
||||||
$output .= "ob_start();\n";
|
$output .= "ob_start();\n";
|
||||||
@@ -157,9 +157,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||||
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
|
$output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
|
||||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
|
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
|
||||||
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
|
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n";
|
||||||
$output .= "}\n}\n";
|
$output .= "}\n}\n";
|
||||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
$output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n";
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$compiler->parser->current_buffer->append_subtree(
|
$compiler->parser->current_buffer->append_subtree(
|
||||||
$compiler->parser,
|
$compiler->parser,
|
||||||
@@ -179,7 +179,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
|
$compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcName} */\n";
|
$output .= $compiler->cStyleComment(" {$_funcName} ") . "\n";
|
||||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||||
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
|
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
|
||||||
$output .= $_paramsCode;
|
$output .= $_paramsCode;
|
||||||
@@ -196,7 +196,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
);
|
);
|
||||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||||
$output = "<?php\n}}\n";
|
$output = "<?php\n}}\n";
|
||||||
$output .= "/*/ {$_funcName} */\n\n";
|
$output .= $compiler->cStyleComment("/ {$_funcName} ") . "\n\n";
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$compiler->parser->current_buffer->append_subtree(
|
$compiler->parser->current_buffer->append_subtree(
|
||||||
$compiler->parser,
|
$compiler->parser,
|
||||||
|
|||||||
@@ -318,14 +318,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
// get compiled code
|
// get compiled code
|
||||||
$compiled_code = "<?php\n\n";
|
$compiled_code = "<?php\n\n";
|
||||||
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
|
$compiled_code .= $compiler->cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n";
|
||||||
$compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
$compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||||
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
||||||
$compiled_code .= "<?php\n";
|
$compiled_code .= "<?php\n";
|
||||||
$compiled_code .= "}\n?>\n";
|
$compiled_code .= "}\n?>\n";
|
||||||
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
|
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
|
||||||
$compiled_code .= "<?php\n\n";
|
$compiled_code .= "<?php\n\n";
|
||||||
$compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
|
$compiled_code .= $compiler->cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n";
|
||||||
$compiled_code .= '?>';
|
$compiled_code .= '?>';
|
||||||
unset($tpl->compiler);
|
unset($tpl->compiler);
|
||||||
if ($tpl->compiled->has_nocache_code) {
|
if ($tpl->compiled->has_nocache_code) {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
if (!empty($_dir)) {
|
if (!empty($_dir)) {
|
||||||
foreach ((array)$_dir as $_script_dir) {
|
foreach ((array)$_dir as $_script_dir) {
|
||||||
$_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;
|
$_script_dir = rtrim($_script_dir ?? '', '/\\') . DIRECTORY_SEPARATOR;
|
||||||
if (file_exists($_script_dir . $_script)) {
|
if (file_exists($_script_dir . $_script)) {
|
||||||
$_filepath = $_script_dir . $_script;
|
$_filepath = $_script_dir . $_script;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
|||||||
}
|
}
|
||||||
// autoescape html
|
// autoescape html
|
||||||
if ($compiler->template->smarty->escape_html) {
|
if ($compiler->template->smarty->escape_html) {
|
||||||
$output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
|
$output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
|
||||||
}
|
}
|
||||||
// loop over registered filters
|
// loop over registered filters
|
||||||
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
|
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
|
||||||
|
|||||||
@@ -157,10 +157,12 @@ class Smarty_Internal_Config_File_Compiler
|
|||||||
$this->smarty->_debug->end_compile($this->template);
|
$this->smarty->_debug->end_compile($this->template);
|
||||||
}
|
}
|
||||||
// template header code
|
// template header code
|
||||||
$template_header =
|
$template_header = sprintf(
|
||||||
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
"<?php /* Smarty version %s, created on %s\n compiled from '%s' */ ?>\n",
|
||||||
"\n";
|
Smarty::SMARTY_VERSION,
|
||||||
$template_header .= " compiled from '{$this->template->source->filepath}' */ ?>\n";
|
date("Y-m-d H:i:s"),
|
||||||
|
str_replace('*/', '* /' , $this->template->source->filepath)
|
||||||
|
);
|
||||||
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
|
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
|
||||||
var_export($this->config_data, true) . '); ?>';
|
var_export($this->config_data, true) . '); ?>';
|
||||||
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);
|
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);
|
||||||
|
|||||||
@@ -44,9 +44,12 @@ class Smarty_Internal_Runtime_CodeFrame
|
|||||||
$properties[ 'file_dependency' ] = $_template->cached->file_dependency;
|
$properties[ 'file_dependency' ] = $_template->cached->file_dependency;
|
||||||
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
$properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
||||||
}
|
}
|
||||||
$output = "<?php\n";
|
$output = sprintf(
|
||||||
$output .= "/* Smarty version {$properties[ 'version' ]}, created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
"<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
|
||||||
"\n from '" . str_replace('*/', '* /', $_template->source->filepath) . "' */\n\n";
|
$properties[ 'version' ],
|
||||||
|
date("Y-m-d H:i:s"),
|
||||||
|
str_replace('*/', '* /', $_template->source->filepath)
|
||||||
|
);
|
||||||
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
$output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
||||||
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
$dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
||||||
($cache ? 'true' : 'false') . ')';
|
($cache ? 'true' : 'false') . ')';
|
||||||
|
|||||||
@@ -29,12 +29,7 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
{
|
{
|
||||||
$_error_reporting = error_reporting();
|
$_error_reporting = error_reporting();
|
||||||
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||||
$_file_perms = property_exists($smarty, '_file_perms') ? $smarty->_file_perms : 0644;
|
$old_umask = umask(0);
|
||||||
$_dir_perms =
|
|
||||||
property_exists($smarty, '_dir_perms') ? (isset($smarty->_dir_perms) ? $smarty->_dir_perms : 0777) : 0771;
|
|
||||||
if ($_file_perms !== null) {
|
|
||||||
$old_umask = umask(0);
|
|
||||||
}
|
|
||||||
$_dirpath = dirname($_filepath);
|
$_dirpath = dirname($_filepath);
|
||||||
// if subdirs, create dir structure
|
// if subdirs, create dir structure
|
||||||
if ($_dirpath !== '.') {
|
if ($_dirpath !== '.') {
|
||||||
@@ -42,7 +37,7 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
// loop if concurrency problem occurs
|
// loop if concurrency problem occurs
|
||||||
// see https://bugs.php.net/bug.php?id=35326
|
// see https://bugs.php.net/bug.php?id=35326
|
||||||
while (!is_dir($_dirpath)) {
|
while (!is_dir($_dirpath)) {
|
||||||
if (@mkdir($_dirpath, $_dir_perms, true)) {
|
if (@mkdir($_dirpath, 0771, true)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
@@ -89,11 +84,9 @@ class Smarty_Internal_Runtime_WriteFile
|
|||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
throw new SmartyException("unable to write file {$_filepath}");
|
throw new SmartyException("unable to write file {$_filepath}");
|
||||||
}
|
}
|
||||||
if ($_file_perms !== null) {
|
// set file permissions
|
||||||
// set file permissions
|
chmod($_filepath, 0644);
|
||||||
chmod($_filepath, $_file_perms);
|
umask($old_umask);
|
||||||
umask($old_umask);
|
|
||||||
}
|
|
||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,9 +422,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
try {
|
try {
|
||||||
// save template object in compiler class
|
// save template object in compiler class
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
if (property_exists($this->template->smarty, 'plugin_search_order')) {
|
|
||||||
$this->plugin_search_order = $this->template->smarty->plugin_search_order;
|
|
||||||
}
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
if (!isset($this->smarty->_debug)) {
|
if (!isset($this->smarty->_debug)) {
|
||||||
$this->smarty->_debug = new Smarty_Internal_Debug();
|
$this->smarty->_debug = new Smarty_Internal_Debug();
|
||||||
@@ -1135,7 +1132,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
$e = new SmartyCompilerException($error_text);
|
$e = new SmartyCompilerException($error_text);
|
||||||
$e->line = $line;
|
$e->setLine($line);
|
||||||
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
|
||||||
$e->desc = $args;
|
$e->desc = $args;
|
||||||
$e->template = $this->template->source->filepath;
|
$e->template = $this->template->source->filepath;
|
||||||
@@ -1439,6 +1436,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
*/
|
*/
|
||||||
abstract protected function doCompile($_content, $isTemplateSource = false);
|
abstract protected function doCompile($_content, $isTemplateSource = false);
|
||||||
|
|
||||||
|
public function cStyleComment($string) {
|
||||||
|
return '/*' . str_replace('*/', '* /' , $string) . '*/';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile Tag
|
* Compile Tag
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2397,6 +2397,9 @@ public static $yy_action = array(
|
|||||||
}
|
}
|
||||||
// line 749 "../smarty/lexer/smarty_internal_templateparser.y"
|
// line 749 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||||
public function yy_r94(){
|
public function yy_r94(){
|
||||||
|
if ($this->security && $this->security->static_classes !== array()) {
|
||||||
|
$this->compiler->trigger_template_error('dynamic static class not allowed by security setting');
|
||||||
|
}
|
||||||
$prefixVar = $this->compiler->getNewPrefixVariable();
|
$prefixVar = $this->compiler->getNewPrefixVariable();
|
||||||
if ($this->yystack[$this->yyidx + -2]->minor['var'] === '\'smarty\'') {
|
if ($this->yystack[$this->yyidx + -2]->minor['var'] === '\'smarty\'') {
|
||||||
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),$this->yystack[$this->yyidx + -2]->minor['smarty_internal_index']).';?>');
|
$this->compiler->appendPrefixCode("<?php {$prefixVar} = ". $this->compiler->compileTag('private_special_variable',array(),$this->yystack[$this->yyidx + -2]->minor['smarty_internal_index']).';?>');
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ class SmartyCompilerException extends SmartyException
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The line number of the template error
|
* @param int $line
|
||||||
*
|
|
||||||
* @type int|null
|
|
||||||
*/
|
*/
|
||||||
public $line = null;
|
public function setLine($line)
|
||||||
|
{
|
||||||
|
$this->line = $line;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* The template source snippet relating to the error
|
* The template source snippet relating to the error
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
|
|||||||
|
|
||||||
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
public function compiledPrefilter($text, Smarty_Internal_Template $tpl)
|
||||||
{
|
{
|
||||||
return str_replace('#', $tpl->getTemplateVars('test'), $text);
|
$replace = $tpl->getTemplateVars('test');
|
||||||
|
return str_replace('#', $replace ?? '', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
|
|||||||
|
|
||||||
public function __construct($directory)
|
public function __construct($directory)
|
||||||
{
|
{
|
||||||
$this->directory = rtrim($directory, "/\\") . DIRECTORY_SEPARATOR;
|
$this->directory = rtrim($directory ?? '', "/\\") . DIRECTORY_SEPARATOR;
|
||||||
// parent::__construct();
|
// parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class ResourceStream
|
|||||||
$v = &$GLOBALS[$this->varname];
|
$v = &$GLOBALS[$this->varname];
|
||||||
$l = strlen($data);
|
$l = strlen($data);
|
||||||
$p = &$this->position;
|
$p = &$this->position;
|
||||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||||
|
|
||||||
return $l;
|
return $l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,19 +257,41 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test not trusted PHP function
|
* test not trusted PHP function
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*/
|
*/
|
||||||
public function testNotTrustedStaticClass()
|
public function testNotTrustedStaticClass()
|
||||||
{
|
{
|
||||||
$this->expectException('SmartyException');
|
$this->expectException('SmartyException');
|
||||||
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassEval()
|
||||||
|
{
|
||||||
|
$this->expectException('SmartyException');
|
||||||
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test not trusted PHP function
|
||||||
|
*/
|
||||||
|
public function testNotTrustedStaticClassSmartyVar()
|
||||||
|
{
|
||||||
|
$this->expectException('SmartyException');
|
||||||
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
|
$this->smarty->fetch('string:{$smarty.template_object::square(5)}');
|
||||||
|
}
|
||||||
|
|
||||||
public function testChangedTrustedDirectory()
|
public function testChangedTrustedDirectory()
|
||||||
{
|
{
|
||||||
$this->smarty->security_policy->secure_dir = array(
|
$this->smarty->security_policy->secure_dir = array(
|
||||||
@@ -344,9 +366,9 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* In security mode, accessing $smarty.template_object should be illegal.
|
* In security mode, accessing $smarty.template_object should be illegal.
|
||||||
* @expectedException SmartyCompilerException
|
|
||||||
*/
|
*/
|
||||||
public function testSmartyTemplateObject() {
|
public function testSmartyTemplateObject() {
|
||||||
|
$this->expectException(SmartyCompilerException::class);
|
||||||
$this->smarty->display('string:{$smarty.template_object}');
|
$this->smarty->display('string:{$smarty.template_object}');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +416,7 @@ class ResourceStreamSecurity
|
|||||||
$v = &$GLOBALS[$this->varname];
|
$v = &$GLOBALS[$this->varname];
|
||||||
$l = strlen($data);
|
$l = strlen($data);
|
||||||
$p = &$this->position;
|
$p = &$this->position;
|
||||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||||
|
|
||||||
return $l;
|
return $l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,9 +435,9 @@ class CompileFunctionTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test handling of function names that are a security risk
|
* Test handling of function names that are a security risk
|
||||||
* @expectedException SmartyCompilerException
|
|
||||||
*/
|
*/
|
||||||
public function testIllegalFunctionName() {
|
public function testIllegalFunctionName() {
|
||||||
|
$this->expectException(SmartyCompilerException::class);
|
||||||
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
|
$this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,30 @@ class MathTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMultipleOperators()
|
||||||
|
{
|
||||||
|
$this->smarty->disableSecurity();
|
||||||
|
$expected = "2 -- 2";
|
||||||
|
$tpl = $this->smarty->createTemplate('eval:{$x = 5}{$y = 4}{math equation="x - y + 1" x=$x y=$y} -- {math equation="5 - 4 + 1"}');
|
||||||
|
$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()
|
public function testSyntaxSin()
|
||||||
{
|
{
|
||||||
$this->smarty->disableSecurity();
|
$this->smarty->disableSecurity();
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class VariableStream
|
|||||||
$v = &$GLOBALS[$this->varname];
|
$v = &$GLOBALS[$this->varname];
|
||||||
$l = strlen($data);
|
$l = strlen($data);
|
||||||
$p = &$this->position;
|
$p = &$this->position;
|
||||||
$v = substr($v, 0, $p) . $data . substr($v, $p += $l);
|
$v = substr($v ?? '', 0, $p) . $data . substr($v ?? '', $p += $l);
|
||||||
|
|
||||||
return $l;
|
return $l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
FROM php:7.1-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,10 @@
|
|||||||
|
FROM php:7.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
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
FROM php:7.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,10 @@
|
|||||||
|
FROM php:7.4-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,10 @@
|
|||||||
|
FROM php:8.0-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,10 @@
|
|||||||
|
FROM php:8.1-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
|
||||||
Executable
+2
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
composer update && php ./vendor/phpunit/phpunit/phpunit
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
|
||||||
|
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||||
|
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
|
||||||
|
|
||||||
|
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
|
||||||
|
then
|
||||||
|
>&2 echo 'ERROR: Invalid installer checksum'
|
||||||
|
rm composer-setup.php
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
php composer-setup.php --quiet
|
||||||
|
RESULT=$?
|
||||||
|
rm composer-setup.php
|
||||||
|
exit $RESULT
|
||||||
Reference in New Issue
Block a user