[+BUGFIX] Compiled HtmlSpecialCharsViewHelper should only work on strings
authorSebastian Kurfuerst <sebastian@typo3.org>
Tue, 2 Aug 2011 09:05:59 +0000 (11:05 +0200)
committerSebastian Kurfuerst <sebastian@typo3.org>
Tue, 2 Aug 2011 09:10:48 +0000 (11:10 +0200)
Change-Id: If7e6ef07c689f363c7a542b911f4c8bb32eb564a

typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlspecialcharsViewHelper.php

index 5730468..9b89d16 100644 (file)
@@ -81,8 +81,11 @@ class Tx_Fluid_ViewHelpers_Format_HtmlspecialcharsViewHelper extends Tx_Fluid_Vi
        }
 
        public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, Tx_Fluid_Core_Parser_SyntaxTree_AbstractNode $syntaxTreeNode, Tx_Fluid_Core_Compiler_TemplateCompiler $templateCompiler) {
-               return sprintf('htmlspecialchars((%s[\'value\'] !== NULL ? %s[\'value\'] : %s()), (%s[\'keepQuotes\'] ? ENT_NOQUOTES : ENT_COMPAT), (%s[\'encoding\'] !== NULL ? %s[\'encoding\'] : Tx_Fluid_Core_Compiler_AbstractCompiledTemplate::resolveDefaultEncoding()), %s[\'doubleEncode\'])',
-                               $argumentsVariableName, $argumentsVariableName, $renderChildrenClosureVariableName, $argumentsVariableName, $argumentsVariableName, $argumentsVariableName, $argumentsVariableName);
+               $valueVariableName = $templateCompiler->variableName('value');
+               $initializationPhpCode .= sprintf('%s = (%s[\'value\'] !== NULL ? %s[\'value\'] : %s());', $valueVariableName, $argumentsVariableName, $argumentsVariableName, $renderChildrenClosureVariableName) . chr(10);
+
+               return sprintf('(!is_string(%s) ? %s : htmlspecialchars(%s, (%s[\'keepQuotes\'] ? ENT_NOQUOTES : ENT_COMPAT), (%s[\'encoding\'] !== NULL ? %s[\'encoding\'] : Tx_Fluid_Core_Compiler_AbstractCompiledTemplate::resolveDefaultEncoding()), %s[\'doubleEncode\']))',
+                               $valueVariableName, $valueVariableName, $valueVariableName, $argumentsVariableName, $argumentsVariableName, $argumentsVariableName, $argumentsVariableName);
        }
 }
 ?>
\ No newline at end of file