bugfix rework of newline spacing between tag code and template text.

now again identical with Smarty2 (forum topic 26878)
This commit is contained in:
Uwe Tews
2017-11-20 04:07:51 +01:00
parent 654659aadf
commit 96fd914cc1
26 changed files with 48 additions and 79 deletions

View File

@@ -1,4 +1,8 @@
===== 3.1.32 - dev ===
20.11.2017
- bugfix rework of newline spacing between tag code and template text.
now again identical with Smarty2 (forum topic 26878)
05.11.2017
- lexer/parser optimization
- code cleanup and optimizations

View File

@@ -340,7 +340,7 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
comment {
preg_match("/[*]{$this->compiler->getRdelPreg()}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
if (isset($match[0][1])) {
$to = $match[0][1] + strlen($match[0][0]);
} else {

View File

@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.32-dev-35';
const SMARTY_VERSION = '3.1.32-dev-36';
/**
* define variable scopes
*/
@@ -921,7 +921,7 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param object $parent next higher level of Smarty variables
* @param boolean $do_clone flag is Smarty object shall be cloned
*
* @return object template object
* @return \Smarty_Internal_Template template object
* @throws \SmartyException
*/
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)

View File

@@ -5,15 +5,15 @@
* @package Smarty
* @subpackage PluginsFilter
*/
/**
* Smarty htmlspecialchars variablefilter plugin
*
* @param string $source input string
* @param string $source input string
* @param \Smarty_Internal_Template $template
*
* @return string filtered output
*/
function smarty_variablefilter_htmlspecialchars($source)
function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET);
}

View File

@@ -85,9 +85,9 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
$output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});\n?>";
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});?>";
} else {
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});\n?>";
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});?>";
}
return $output;
}

View File

@@ -123,7 +123,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
$compiler->trigger_template_error(" '\$smarty.block.{$name}' used outside {block} tags ",
$compiler->parser->lex->taglineno);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
switch ($name) {
case 'child':
@@ -235,7 +234,6 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
if ($compiler->_cache['blockNesting'] === 0) {
unset($compiler->_cache['blockNesting']);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;
}

View File

@@ -112,7 +112,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
", {$template}{$inlineUids}" :
'') . ");\n?>\n");
'') . ");\n?>");
}
/**

View File

@@ -164,7 +164,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
if ($openTag !== 'forelse') {
$output .= "}\n";
}
$output .= "?>\n";
$output .= "?>";
return $output;
}
}

View File

@@ -262,7 +262,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
*/
public function compileRestore($levels)
{
return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});\n";
return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});";
}
}
@@ -293,7 +293,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>\n";
$output .= "}\n} else {\n?>";
return $output;
}
}
@@ -337,7 +337,7 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore(1);
$output .= "?>\n";
$output .= "?>";
return $output;
}
}

View File

@@ -132,7 +132,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "/* {$_funcNameCaching} */\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= "ob_start();\n";
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
$output .= $_paramsCode;
@@ -164,7 +164,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "/* {$_funcName} */\n";
$output .= "if (!function_exists('{$_funcName}')) {\n";
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser,

View File

@@ -239,7 +239,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
}
$_output .= "?>\n";
$_output .= "?>";
return $_output;
}
if ($call_nocache) {
@@ -260,7 +260,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
}
$_output .= "?>\n";
$_output .= "?>";
return $_output;
}
@@ -305,7 +305,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// get compiled code
$compiled_code = "<?php\n\n";
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_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 .= "<?php\n";
$compiled_code .= "}\n?>\n";

View File

@@ -52,8 +52,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
if (!$nocacheParam) {
// do not compile as nocache code

View File

@@ -16,7 +16,7 @@
*/
class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
{
/**
/**
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
@@ -32,9 +32,6 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;
return $compiler->smarty->left_delimiter;
}
}

View File

@@ -52,7 +52,6 @@ class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase
$_attr = $this->getAttributes($compiler, $args);
if ($compiler->template->caching) {
$output = "<?php \$_smarty_tpl->smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n";
$compiler->has_code = true;
$compiler->template->compiled->has_nocache_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;

View File

@@ -65,7 +65,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n";
}
$output .= "\$_smarty_tpl->smarty->_cache['_tag_stack'][] = array('{$tag}', {$_params});\n";
$output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();\n?>";
$output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>";
$this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
// maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
@@ -76,8 +76,6 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
}
// closing tag of block plugin, restore nocache
list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5));
//Does tag create output
$compiler->has_output = isset($_params[ 'assign' ]) ? false : true;
// compile code
if (!isset($parameter[ 'modifier_list' ])) {
$mod_pre = $mod_post = $mod_content = '';
@@ -93,7 +91,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$output = "<?php {$mod_content}\$_block_repeat=false;\n{$mod_pre}echo {$callback}({$_params}, {$mod_content2}, \$_smarty_tpl, \$_block_repeat);\n{$mod_post}}\n";
$output .= 'array_pop($_smarty_tpl->smarty->_cache[\'_tag_stack\']);?>';
}
return $output . "\n";
return $output;
}
/**

View File

@@ -68,8 +68,6 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}

View File

@@ -41,9 +41,6 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
unset($_attr[ 'nocache' ]);
$_assign = null;
if (isset($_attr[ 'assign' ])) {
@@ -76,9 +73,6 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
}
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
if (empty($_assign)) {
return "<?php echo {$output};?>\n";
} else {

View File

@@ -120,9 +120,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
}
$compiler->has_output = true;
$output = "<?php echo {$output};?>";
$output = "<?php echo {$output};?>\n";
}
return $output;

View File

@@ -80,8 +80,6 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}

View File

@@ -14,7 +14,7 @@
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim
{
/**
* Compiles code for the {rdelim} tag
@@ -28,13 +28,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;
parent::compile($args,$compiler);
return $compiler->smarty->right_delimiter;
}
}

View File

@@ -27,14 +27,15 @@
* Method extensions
* @property Smarty_Internal_Method_GetTemplateVars $getTemplateVars
* @property Smarty_Internal_Method_Append $append
* @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_LoadPlugin $loadPlugin
* @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
* @property Smarty_Internal_Method_AppendByRef $appendByRef
* @property Smarty_Internal_Method_AssignGlobal $assignGlobal
* @property Smarty_Internal_Method_AssignByRef $assignByRef
* @property Smarty_Internal_Method_LoadFilter $loadFilter
* @property Smarty_Internal_Method_LoadPlugin $loadPlugin
* @property Smarty_Internal_Method_RegisterFilter $registerFilter
* @property Smarty_Internal_Method_RegisterObject $registerObject
* @property Smarty_Internal_Method_RegisterPlugin $registerPlugin
* @property mixed|\Smarty_Template_Cached configLoad
*/
class Smarty_Internal_Extension_Handler
{

View File

@@ -88,7 +88,7 @@ class Smarty_Internal_Runtime_CodeFrame
$output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
}
}
$output .= "?>\n";
$output .= "?>";
$output .= $content;
$output .= "<?php }\n?>";
$output .= $functions;

View File

@@ -17,6 +17,7 @@
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
* @property Smarty_Internal_TemplateCompilerBase $compiler
* @property mixed|\Smarty_Template_Cached registered_plugins
*
* The following methods will be dynamically loaded by the extension handler when they are called.
* They are located in a corresponding Smarty_Internal_Method_xxxx class

View File

@@ -225,12 +225,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var bool
*/
public $has_variable_string = false;
/**
* Tag creates output
*
* @var bool
*/
public $has_output = false;
/**
* Stack for {setfilter} {/setfilter}
*
@@ -833,9 +828,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function appendCode($left, $right)
{
if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) {
$left = preg_replace('/\s*\?>\s*$/', "\n", $left);
$left .= preg_replace('/^\s*<\?php\s+/', '', $right);
if (preg_match('/\s*\?>\s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) {
$left = preg_replace('/\s*\?>\s?$/D', "\n", $left);
$left .= preg_replace('/^<\?php\s+/', '', $right);
} else {
$left .= $right;
}
@@ -1298,7 +1293,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
// $args contains the attributes parsed and compiled by the lexer/parser
// assume that tag does compile into code, but creates no HTML output
$this->has_code = true;
$this->has_output = false;
// log tag/attributes
if (isset($this->smarty->_cache[ 'get_used_tags' ])) {
$this->template->_cache[ 'used_tags' ][] = array($tag,
@@ -1333,10 +1327,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($_output !== true) {
// did we get compiled code
if ($this->has_code) {
// Does it create output?
if ($this->has_output) {
$_output .= "\n";
}
// return compiled code
return $_output;
}

View File

@@ -368,7 +368,11 @@ class Smarty_Internal_Templatelexer
function yy_r1_2()
{
preg_match("/[*]{$this->compiler->getRdelPreg()}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
preg_match("/[*]{$this->compiler->getRdelPreg()}[\n]?/",
$this->data,
$match,
PREG_OFFSET_CAPTURE,
$this->counter);
if (isset($match[ 0 ][ 1 ])) {
$to = $match[ 0 ][ 1 ] + strlen($match[ 0 ][ 0 ]);
} else {

View File

@@ -9,9 +9,6 @@ class TP_yyStackEntry
** is the value of the token */
}
;
#line 11 "../smarty/lexer/smarty_internal_templateparser.y"
/**
* Smarty Template Parser Class
*