Skip to content

Commit

Permalink
bugfix rework of newline spacing between tag code and template text.
Browse files Browse the repository at this point in the history
now again identical with Smarty2 (forum topic 26878)
  • Loading branch information
Uwe Tews committed Nov 20, 2017
1 parent 654659a commit 96fd914
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 79 deletions.
4 changes: 4 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lexer/smarty_internal_templatelexer.plex
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -921,7 +921,7 @@ public function setCacheDir($cache_dir)
* @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)
Expand Down
6 changes: 3 additions & 3 deletions libs/plugins/variablefilter.htmlspecialchars.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_compile_assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$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;
}
Expand Down
2 changes: 0 additions & 2 deletions libs/sysplugins/smarty_internal_compile_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBa
$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':
Expand Down Expand Up @@ -235,7 +234,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($compiler->_cache['blockNesting'] === 0) {
unset($compiler->_cache['blockNesting']);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_compile_extends.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler,
'<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl' .
(isset($template) ?
", {$template}{$inlineUids}" :
'') . ");\n?>\n");
'') . ");\n?>");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_compile_for.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function compile($args, $compiler, $parameter)
if ($openTag !== 'forelse') {
$output .= "}\n";
}
$output .= "?>\n";
$output .= "?>";
return $output;
}
}
6 changes: 3 additions & 3 deletions libs/sysplugins/smarty_internal_compile_foreach.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
*/
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});";
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>\n";
$output .= "}\n} else {\n?>";
return $output;
}
}
Expand Down Expand Up @@ -337,7 +337,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore(1);
$output .= "?>\n";
$output .= "?>";
return $output;
}
}
4 changes: 2 additions & 2 deletions libs/sysplugins/smarty_internal_compile_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
$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;
Expand Down Expand Up @@ -164,7 +164,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
$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,
Expand Down
6 changes: 3 additions & 3 deletions libs/sysplugins/smarty_internal_compile_include.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler)
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) {
Expand All @@ -260,7 +260,7 @@ public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler)
if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
}
$_output .= "?>\n";
$_output .= "?>";
return $_output;
}

Expand Down Expand Up @@ -305,7 +305,7 @@ public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $co
// 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";
Expand Down
2 changes: 0 additions & 2 deletions libs/sysplugins/smarty_internal_compile_insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// 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
Expand Down
5 changes: 1 addition & 4 deletions libs/sysplugins/smarty_internal_compile_ldelim.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -32,9 +32,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
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;
}
}
1 change: 0 additions & 1 deletion libs/sysplugins/smarty_internal_compile_make_nocache.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
$_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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$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;
Expand All @@ -76,8 +76,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
}
// 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 = '';
Expand All @@ -93,7 +91,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
{
// 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' ])) {
Expand Down Expand Up @@ -76,9 +73,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
}
}
}

$compiler->has_output = true;
$output = "<?php echo {$output};?>";
$output = "<?php echo {$output};?>\n";
}

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = true;
$output = "<?php echo {$output};?>\n";
return $output;
}
Expand Down
10 changes: 2 additions & 8 deletions libs/sysplugins/smarty_internal_compile_rdelim.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
17 changes: 9 additions & 8 deletions libs/sysplugins/smarty_internal_extension_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_runtime_codeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function create(Smarty_Internal_Template $_template, $content = '', $func
$output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
}
}
$output .= "?>\n";
$output .= "?>";
$output .= $content;
$output .= "<?php }\n?>";
$output .= $functions;
Expand Down
1 change: 1 addition & 0 deletions libs/sysplugins/smarty_internal_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions libs/sysplugins/smarty_internal_templatecompilerbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -833,9 +828,9 @@ public function getPluginFromDefaultHandler($tag, $plugin_type)
*/
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;
}
Expand Down Expand Up @@ -1298,7 +1293,6 @@ private function compileTag2($tag, $args, $parameter)
// $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,
Expand Down Expand Up @@ -1333,10 +1327,6 @@ private function compileTag2($tag, $args, $parameter)
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;
}
Expand Down
Loading

0 comments on commit 96fd914

Please sign in to comment.