Skip to content

Commit

Permalink
- bugfix broken PHP 5.2 compatibility when compiling <?php tags #40
Browse files Browse the repository at this point in the history
  • Loading branch information
uwetews committed May 20, 2015
1 parent 85e0545 commit 5d8718f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.2
- 5.3
- 5.4
- 5.5
Expand Down
3 changes: 3 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
 ===== 3.1.24.dev ===== (xx.xx.2015)
21.05.2015
- bugfix broken PHP 5.2 compatibility when compiling <?php tags https://github.com/smarty-php/smarty/issues/40

19.05.2015
- bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39
- bugfix output filter trimwhitespace could run into the pcre.backtrack_limit on large output (code.google issue 220)
Expand Down
20 changes: 17 additions & 3 deletions libs/sysplugins/smarty_internal_compile_private_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
{

/**
* Attribute definition: Overwrites base class.
*
Expand Down Expand Up @@ -50,11 +51,14 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$this->php_handling = $compiler->smarty->php_handling;
}
if ($this->php_handling == Smarty::PHP_REMOVE) {
$output = preg_replace(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#', '#(\?>)|(%>)|(<\/script>)$#'), '', $_attr['code']);
$output = preg_replace(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#',
'#(\?>)|(%>)|(<\/script>)$#'), '', $_attr['code']);
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
return '';
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
$output = preg_replace_callback(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#', '#(\?>)|(%>)|(<\/script>)$#'), function ($match) {return htmlspecialchars($match[0], ENT_QUOTES);}, $_attr['code']);
$output = preg_replace_callback(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#',
'#(\?>)|(%>)|(<\/script>)$#'), array($this,
'quote'), $_attr['code']);
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
return '';
} elseif ($this->php_handling == Smarty::PHP_PASSTHRU || ($_attr['type'] == 'asp' && !$this->asp_tags) || $_attr['type'] == 'unmatched') {
Expand Down Expand Up @@ -86,7 +90,17 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno);
}
}
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#",
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
}
}

/*
* Call back function for $php_handling = PHP_QUOTE
*
*/
private function quote($match)
{
return htmlspecialchars($match[0], ENT_QUOTES);
}
}

0 comments on commit 5d8718f

Please sign in to comment.