File size: 48,145 Bytes
4d2a9bf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | diff --git a/src/Core/Parser/Configuration.php b/src/Core/Parser/Configuration.php
index 49850cf7e..33e095377 100644
--- a/src/Core/Parser/Configuration.php
+++ b/src/Core/Parser/Configuration.php
@@ -12,6 +12,10 @@
*/
class Configuration
{
+ /**
+ * @var bool
+ */
+ protected $viewHelperArgumentEscapingEnabled = true;
/**
* Generic interceptors registered with the configuration.
@@ -27,6 +31,22 @@ class Configuration
*/
protected $escapingInterceptors = [];
+ /**
+ * @return bool
+ */
+ public function isViewHelperArgumentEscapingEnabled()
+ {
+ return $this->viewHelperArgumentEscapingEnabled;
+ }
+
+ /**
+ * @param bool $viewHelperArgumentEscapingEnabled
+ */
+ public function setViewHelperArgumentEscapingEnabled($viewHelperArgumentEscapingEnabled): void
+ {
+ $this->viewHelperArgumentEscapingEnabled = (bool) $viewHelperArgumentEscapingEnabled;
+ }
+
/**
* Adds an interceptor to apply to values coming from object accessors.
*
diff --git a/src/Core/Parser/TemplateParser.php b/src/Core/Parser/TemplateParser.php
index aee1c21cb..22be29cf3 100644
--- a/src/Core/Parser/TemplateParser.php
+++ b/src/Core/Parser/TemplateParser.php
@@ -489,7 +489,7 @@ protected function objectAccessorHandler(ParsingState $state, $objectAccessorStr
}
$viewHelper = $viewHelperResolver->createViewHelperInstance($singleMatch['NamespaceIdentifier'], $singleMatch['MethodIdentifier']);
if (strlen($singleMatch['ViewHelperArguments']) > 0) {
- $arguments = $this->recursiveArrayHandler($singleMatch['ViewHelperArguments'], $viewHelper);
+ $arguments = $this->recursiveArrayHandler($state, $singleMatch['ViewHelperArguments'], $viewHelper);
} else {
$arguments = [];
}
@@ -563,28 +563,43 @@ protected function parseArguments($argumentsString, ViewHelperInterface $viewHel
$undeclaredArguments = [];
$matches = [];
if (preg_match_all(Patterns::$SPLIT_PATTERN_TAGARGUMENTS, $argumentsString, $matches, PREG_SET_ORDER) > 0) {
- $escapingEnabledBackup = $this->escapingEnabled;
- $this->escapingEnabled = false;
foreach ($matches as $singleMatch) {
$argument = $singleMatch['Argument'];
$value = $this->unquoteString($singleMatch['ValueQuoted']);
- $argumentsObjectTree[$argument] = $this->buildArgumentObjectTree($value);
+ $escapingEnabledBackup = $this->escapingEnabled;
if (isset($argumentDefinitions[$argument])) {
$argumentDefinition = $argumentDefinitions[$argument];
- if ($argumentDefinition->getType() === 'boolean' || $argumentDefinition->getType() === 'bool') {
+ $this->escapingEnabled = $this->escapingEnabled && $this->isArgumentEscaped($viewHelper, $argumentDefinition);
+ $isBoolean = $argumentDefinition->getType() === 'boolean' || $argumentDefinition->getType() === 'bool';
+ $argumentsObjectTree[$argument] = $this->buildArgumentObjectTree($value);
+ if ($isBoolean) {
$argumentsObjectTree[$argument] = new BooleanNode($argumentsObjectTree[$argument]);
}
} else {
- $undeclaredArguments[$argument] = $argumentsObjectTree[$argument];
+ $this->escapingEnabled = false;
+ $undeclaredArguments[$argument] = $this->buildArgumentObjectTree($value);
}
+ $this->escapingEnabled = $escapingEnabledBackup;
}
- $this->escapingEnabled = $escapingEnabledBackup;
}
$this->abortIfRequiredArgumentsAreMissing($argumentDefinitions, $argumentsObjectTree);
$viewHelper->validateAdditionalArguments($undeclaredArguments);
return $argumentsObjectTree + $undeclaredArguments;
}
+ protected function isArgumentEscaped(ViewHelperInterface $viewHelper, ArgumentDefinition $argumentDefinition = null)
+ {
+ $hasDefinition = $argumentDefinition instanceof ArgumentDefinition;
+ $isBoolean = $hasDefinition && ($argumentDefinition->getType() === 'boolean' || $argumentDefinition->getType() === 'bool');
+ $escapingEnabled = $this->configuration->isViewHelperArgumentEscapingEnabled();
+ $isArgumentEscaped = $hasDefinition && $argumentDefinition->getEscape() === true;
+ $isContentArgument = $hasDefinition && method_exists($viewHelper, 'resolveContentArgumentName') && $argumentDefinition->getName() === $viewHelper->resolveContentArgumentName();
+ if ($isContentArgument) {
+ return !$isBoolean && ($viewHelper->isChildrenEscapingEnabled() || $isArgumentEscaped);
+ }
+ return !$isBoolean && $escapingEnabled && $isArgumentEscaped;
+ }
+
/**
* Build up an argument object tree for the string in $argumentString.
* This builds up the tree for a single argument value.
@@ -664,7 +679,7 @@ protected function textAndShorthandSyntaxHandler(ParsingState $state, $text, $co
&& preg_match(Patterns::$SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS, $section, $matchedVariables) > 0
) {
// We only match arrays if we are INSIDE viewhelper arguments
- $this->arrayHandler($state, $this->recursiveArrayHandler($matchedVariables['Array']));
+ $this->arrayHandler($state, $this->recursiveArrayHandler($state, $matchedVariables['Array']));
} else {
// We ask custom ExpressionNode instances from ViewHelperResolver
// if any match our expression:
@@ -737,12 +752,13 @@ protected function arrayHandler(ParsingState $state, $arrayText)
* - Variables
* - sub-arrays
*
+ * @param ParsingState $state
* @param string $arrayText Array text
* @param ViewHelperInterface|null $viewHelper ViewHelper instance - passed only if the array is a collection of arguments for an inline ViewHelper
* @return NodeInterface[] the array node built up
* @throws Exception
*/
- protected function recursiveArrayHandler($arrayText, ViewHelperInterface $viewHelper = null)
+ protected function recursiveArrayHandler(ParsingState $state, $arrayText, ViewHelperInterface $viewHelper = null)
{
$undeclaredArguments = [];
$argumentDefinitions = [];
@@ -755,14 +771,25 @@ protected function recursiveArrayHandler($arrayText, ViewHelperInterface $viewHe
foreach ($matches as $singleMatch) {
$arrayKey = $this->unquoteString($singleMatch['Key']);
$assignInto = &$arrayToBuild;
- if (!isset($argumentDefinitions[$arrayKey])) {
+ $isBoolean = false;
+ $argumentDefinition = null;
+ if (isset($argumentDefinitions[$arrayKey])) {
+ $argumentDefinition = $argumentDefinitions[$arrayKey];
+ $isBoolean = $argumentDefinitions[$arrayKey]->getType() === 'boolean' || $argumentDefinitions[$arrayKey]->getType() === 'bool';
+ } else {
$assignInto = &$undeclaredArguments;
}
+ $escapingEnabledBackup = $this->escapingEnabled;
+ $this->escapingEnabled = $this->escapingEnabled && $viewHelper instanceof ViewHelperInterface && $this->isArgumentEscaped($viewHelper, $argumentDefinition);
+
if (array_key_exists('Subarray', $singleMatch) && !empty($singleMatch['Subarray'])) {
- $assignInto[$arrayKey] = new ArrayNode($this->recursiveArrayHandler($singleMatch['Subarray']));
+ $assignInto[$arrayKey] = new ArrayNode($this->recursiveArrayHandler($state, $singleMatch['Subarray']));
} elseif (!empty($singleMatch['VariableIdentifier'])) {
$assignInto[$arrayKey] = new ObjectAccessorNode($singleMatch['VariableIdentifier']);
+ if ($viewHelper instanceof ViewHelperInterface && !$isBoolean) {
+ $this->callInterceptor($assignInto[$arrayKey], InterceptorInterface::INTERCEPT_OBJECTACCESSOR, $state);
+ }
} elseif (array_key_exists('Number', $singleMatch) && (!empty($singleMatch['Number']) || $singleMatch['Number'] === '0')) {
// Note: this method of casting picks "int" when value is a natural number and "float" if any decimals are found. See also NumericNode.
$assignInto[$arrayKey] = $singleMatch['Number'] + 0;
@@ -771,9 +798,11 @@ protected function recursiveArrayHandler($arrayText, ViewHelperInterface $viewHe
$assignInto[$arrayKey] = $this->buildArgumentObjectTree($argumentString);
}
- if (isset($argumentDefinitions[$arrayKey]) && ($argumentDefinitions[$arrayKey]->getType() === 'boolean' || $argumentDefinitions[$arrayKey]->getType() === 'bool')) {
+ if ($isBoolean) {
$assignInto[$arrayKey] = new BooleanNode($assignInto[$arrayKey]);
}
+
+ $this->escapingEnabled = $escapingEnabledBackup;
}
}
if ($viewHelper instanceof ViewHelperInterface) {
diff --git a/src/Core/ViewHelper/AbstractConditionViewHelper.php b/src/Core/ViewHelper/AbstractConditionViewHelper.php
index debffb7da..54fe13203 100644
--- a/src/Core/ViewHelper/AbstractConditionViewHelper.php
+++ b/src/Core/ViewHelper/AbstractConditionViewHelper.php
@@ -42,8 +42,8 @@ abstract class AbstractConditionViewHelper extends AbstractViewHelper
*/
public function initializeArguments()
{
- $this->registerArgument('then', 'mixed', 'Value to be returned if the condition if met.', false);
- $this->registerArgument('else', 'mixed', 'Value to be returned if the condition if not met.', false);
+ $this->registerArgument('then', 'mixed', 'Value to be returned if the condition if met.', false, null, true);
+ $this->registerArgument('else', 'mixed', 'Value to be returned if the condition if not met.', false, null, true);
}
/**
diff --git a/src/Core/ViewHelper/AbstractViewHelper.php b/src/Core/ViewHelper/AbstractViewHelper.php
index 975ecc22e..8edd703ce 100644
--- a/src/Core/ViewHelper/AbstractViewHelper.php
+++ b/src/Core/ViewHelper/AbstractViewHelper.php
@@ -158,11 +158,12 @@ public function isOutputEscapingEnabled()
* @param string $description Description of the argument
* @param boolean $required If TRUE, argument is required. Defaults to FALSE.
* @param mixed $defaultValue Default value of argument
+ * @param bool|null $escape Can be toggled to TRUE to force escaping of variables and inline syntax passed as argument value.
* @return \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper $this, to allow chaining.
* @throws Exception
* @api
*/
- protected function registerArgument($name, $type, $description, $required = false, $defaultValue = null)
+ protected function registerArgument($name, $type, $description, $required = false, $defaultValue = null, $escape = null)
{
if (array_key_exists($name, $this->argumentDefinitions)) {
throw new Exception(
@@ -170,7 +171,7 @@ protected function registerArgument($name, $type, $description, $required = fals
1253036401
);
}
- $this->argumentDefinitions[$name] = new ArgumentDefinition($name, $type, $description, $required, $defaultValue);
+ $this->argumentDefinitions[$name] = new ArgumentDefinition($name, $type, $description, $required, $defaultValue, $escape);
return $this;
}
@@ -184,11 +185,12 @@ protected function registerArgument($name, $type, $description, $required = fals
* @param string $description Description of the argument
* @param boolean $required If TRUE, argument is required. Defaults to FALSE.
* @param mixed $defaultValue Default value of argument
+ * @param bool|null $escape Can be toggled to TRUE to force escaping of variables and inline syntax passed as argument value.
* @return \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper $this, to allow chaining.
* @throws Exception
* @api
*/
- protected function overrideArgument($name, $type, $description, $required = false, $defaultValue = null)
+ protected function overrideArgument($name, $type, $description, $required = false, $defaultValue = null, $escape = null)
{
if (!array_key_exists($name, $this->argumentDefinitions)) {
throw new Exception(
@@ -196,7 +198,7 @@ protected function overrideArgument($name, $type, $description, $required = fals
1279212461
);
}
- $this->argumentDefinitions[$name] = new ArgumentDefinition($name, $type, $description, $required, $defaultValue);
+ $this->argumentDefinitions[$name] = new ArgumentDefinition($name, $type, $description, $required, $defaultValue, $escape);
return $this;
}
diff --git a/src/Core/ViewHelper/ArgumentDefinition.php b/src/Core/ViewHelper/ArgumentDefinition.php
index 13933b885..2f85b02b5 100644
--- a/src/Core/ViewHelper/ArgumentDefinition.php
+++ b/src/Core/ViewHelper/ArgumentDefinition.php
@@ -47,6 +47,21 @@ class ArgumentDefinition
*/
protected $defaultValue = null;
+ /**
+ * Escaping instruction, in line with $this->escapeOutput / $this->escapeChildren on ViewHelpers.
+ *
+ * A value of NULL means "use default behavior" (which is to escape nodes contained in the value).
+ *
+ * A value of TRUE means "escape unless escaping is disabled" (e.g. if argument is used in a ViewHelper nested
+ * within f:format.raw which disables escaping, the argument will not be escaped).
+ *
+ * A value of FALSE means "never escape argument" (as in behavior of f:format.raw, which supports both passing
+ * argument as actual argument or as tag content, but wants neither to be escaped).
+ *
+ * @var bool|null
+ */
+ protected $escape = null;
+
/**
* Constructor for this argument definition.
*
@@ -55,14 +70,16 @@ class ArgumentDefinition
* @param string $description Description of argument
* @param boolean $required TRUE if argument is required
* @param mixed $defaultValue Default value
+ * @param bool|null $escape Whether or not argument is escaped, or uses default escaping behavior (see class var comment)
*/
- public function __construct($name, $type, $description, $required, $defaultValue = null)
+ public function __construct($name, $type, $description, $required, $defaultValue = null, $escape = null)
{
$this->name = $name;
$this->type = $type;
$this->description = $description;
$this->required = $required;
$this->defaultValue = $defaultValue;
+ $this->escape = $escape;
}
/**
@@ -114,4 +131,12 @@ public function getDefaultValue()
{
return $this->defaultValue;
}
+
+ /**
+ * @return bool|null
+ */
+ public function getEscape()
+ {
+ return $this->escape;
+ }
}
diff --git a/src/Core/ViewHelper/TagBuilder.php b/src/Core/ViewHelper/TagBuilder.php
index 6916696b4..2c845eda9 100644
--- a/src/Core/ViewHelper/TagBuilder.php
+++ b/src/Core/ViewHelper/TagBuilder.php
@@ -191,6 +191,9 @@ public function ignoreEmptyAttributes($ignoreEmptyAttributes)
*/
public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = true)
{
+ if ($escapeSpecialCharacters) {
+ $attributeName = htmlspecialchars($attributeName);
+ }
if ($attributeName === 'data' && (is_array($attributeValue) || $attributeValue instanceof \Traversable)) {
foreach ($attributeValue as $name => $value) {
$this->addAttribute('data-' . $name, $value, $escapeSpecialCharacters);
diff --git a/src/Core/ViewHelper/Traits/CompileWithContentArgumentAndRenderStatic.php b/src/Core/ViewHelper/Traits/CompileWithContentArgumentAndRenderStatic.php
index b5567dba9..d37957873 100644
--- a/src/Core/ViewHelper/Traits/CompileWithContentArgumentAndRenderStatic.php
+++ b/src/Core/ViewHelper/Traits/CompileWithContentArgumentAndRenderStatic.php
@@ -116,7 +116,7 @@ protected function buildRenderChildrenClosure()
/**
* @return string
*/
- protected function resolveContentArgumentName()
+ public function resolveContentArgumentName()
{
if (empty($this->contentArgumentName)) {
$registeredArguments = call_user_func_array([$this, 'prepareArguments'], []);
diff --git a/src/ViewHelpers/Format/RawViewHelper.php b/src/ViewHelpers/Format/RawViewHelper.php
index 812a519dd..b80c08261 100644
--- a/src/ViewHelpers/Format/RawViewHelper.php
+++ b/src/ViewHelpers/Format/RawViewHelper.php
@@ -64,7 +64,7 @@ class RawViewHelper extends AbstractViewHelper
*/
public function initializeArguments()
{
- $this->registerArgument('value', 'mixed', 'The value to output');
+ $this->registerArgument('value', 'mixed', 'The value to output', false, null, false);
}
/**
diff --git a/tests/Functional/Cases/Escaping/EscapingTest.php b/tests/Functional/Cases/Escaping/EscapingTest.php
index ad00608ea..645312b10 100644
--- a/tests/Functional/Cases/Escaping/EscapingTest.php
+++ b/tests/Functional/Cases/Escaping/EscapingTest.php
@@ -7,6 +7,7 @@
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
use TYPO3Fluid\Fluid\Tests\Functional\BaseFunctionalTestCase;
use TYPO3Fluid\Fluid\Tests\Functional\Fixtures\ViewHelpers\MutableTestViewHelper;
+use TYPO3Fluid\Fluid\Tests\Functional\Fixtures\ViewHelpers\TagBasedTestViewHelper;
use TYPO3Fluid\Fluid\Tests\Functional\Fixtures\ViewHelpers\TestViewHelperResolver;
use TYPO3Fluid\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture;
use TYPO3Fluid\Fluid\View\TemplateView;
@@ -64,13 +65,13 @@ public function testWithEscapingBehaviorsNullWithoutContentOrOutputArguments()
public function testWithEscapingBehaviorsNullWithOutputArgument()
{
+ // When both escapeOutput and escapeChildren are null, output escaping is enabled and children escaping is disabled (because output is escaped there is no need to escsape children explicitly).
+ // The case therefore escapes both static HTML and variables/inline in arguments.
$viewHelper = (new MutableTestViewHelper())->withOutputArgument();
$this->assertSame(self::ESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag with variable');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
-
- // TODO: possible undesired behavior, double encoded variable
- $this->assertSame('<div>&lt;script&gt;alert(1)&lt;/script&gt;</div>', $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ $this->assertSame(self::ESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
}
public function testWithEscapingBehaviorsNullWithContentArgument()
@@ -83,6 +84,7 @@ public function testWithEscapingBehaviorsNullWithContentArgument()
/*
* Escape children = false
* Escape output = null
+ * Escape argument = null
*/
public function testWithEscapChildrenFalseWithoutContentOrOutputArguments()
@@ -102,22 +104,23 @@ public function testWithEscapChildrenFalseWithContentArgument()
public function testWithEscapeChildrenFalseWithOutputArgument()
{
+ // Output argument is not escaped (it is not a content argument) because output escaping is OFF. Developer who wrote ViewHelper would be responsible for escaping.
$viewHelper = (new MutableTestViewHelper())->withOutputArgument()->withEscapeChildren(false);
$this->assertSame(self::ESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
-
- // TODO: possible undesired behavior, double encoded variable
- $this->assertSame('<div>&lt;script&gt;alert(1)&lt;/script&gt;</div>', $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ $this->assertSame(self::ESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
}
/*
* Escape children = null
* Escape output = false
+ * Escape arguments = false
*/
public function testWithEscapOutputFalseWithoutContentOrOutputArguments()
{
+ // Child content and content argument are treated the same based on escape-children state. Children escaping is ON because escape output is OFF and escape children has no decision.
$viewHelper = (new MutableTestViewHelper())->withEscapeOutput(false);
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test>{value}</test:test>'), 'Tag child variable');
@@ -128,39 +131,34 @@ public function testWithEscapOutputFalseWithoutContentOrOutputArguments()
public function testWithEscapeOutputFalseWithContentArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withContentArgument()->withEscapeOutput(false);
+ // Child content and content argument are treated the same based on escape-children state. Children escaping is ON because escape output is OFF and escape children has no decision.
+ $viewHelper = (new MutableTestViewHelper())->withContentArgument(false)->withEscapeOutput(false);
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
-
- // TODO: security case - argument must be escaped!
- #$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(content: value)}'), 'Inline pass of variable');
-
- // TODO: inconsistent case - argument is quoted and is escaped, which does not happen if the argument is NOT quoted
- $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(content: "{value}")}'), 'Inline pass of variable');
-
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(content: value)}'), 'Inline variable in argument');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(content: "{value}")}'), 'Inline pass of variable, quoted');
$this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '<test:test><div>{value}</div></test:test>'), 'Tag child variable with static HTML');
}
public function testWithEscapeOutputFalseWithOutputArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withOutputArgument()->withEscapeOutput(false);
+ // Output argument is not escaped (it is not a content argument) because output escaping is OFF. Developer who wrote ViewHelper would be responsible for escaping.
+ $viewHelper = (new MutableTestViewHelper())->withOutputArgument(false)->withEscapeOutput(false);
$this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
-
- // TODO: inconsistent case - argument is quoted and is escaped, which does not happen if the argument is NOT quoted
- $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: "{value}")}'), 'Inline output argument');
-
- // TODO: possibly undesired behavior, escapes argument though output should be unescaped / children should be escaped but value is not passed as child
- $this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(output: "{value}")}'), 'Inline output argument');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
}
/*
* Escape children = true
* Escape output = false
+ * Escape arguments = false
*/
public function testWithEscapOutputFalseWithEscapeChildrenTrueWithoutContentOrOutputArguments()
{
+ // Output is escaped because children are escaped. Children are escaped because escape-output is OFF and no explicit decision is made for escape-children, causing escape-children to be ON.
$viewHelper = (new MutableTestViewHelper())->withEscapeOutput(false)->withEscapeChildren(true);
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test>{value}</test:test>'), 'Tag child variable');
@@ -169,34 +167,31 @@ public function testWithEscapOutputFalseWithEscapeChildrenTrueWithoutContentOrOu
public function testWithEscapeOutputFalseWithEscapeChildrenTrueWithContentArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withContentArgument()->withEscapeOutput(false)->withEscapeChildren(true);
+ // Child content is escaped because escape-output is OFF but an explicit decision for escape-children has been made to turn it ON.
+ $viewHelper = (new MutableTestViewHelper())->withContentArgument(false)->withEscapeOutput(false)->withEscapeChildren(true);
$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
$this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '<test:test><div>{value}</div></test:test>'), 'Tag child variable with static HTML');
}
public function testWithEscapeOutputFalseWithEscapeChildrenTrueWithOutputArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withOutputArgument()->withEscapeOutput(false)->withEscapeChildren(true);
+ // Output argument is not escaped (it is not a content argument) because escape-output is OFF and escape-children is not considered (it is an argument, not a child). Developer who wrote ViewHelper would be responsible for escaping.
+ $viewHelper = (new MutableTestViewHelper())->withOutputArgument(false)->withEscapeOutput(false)->withEscapeChildren(true);
$this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
-
- // TODO: security case - argument must be escaped!
- #$this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
-
- // TODO: inconsistent case - argument is quoted and is escaped, which does not happen if the argument is NOT quoted
- $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: "{value}")}'), 'Inline output argument');
-
- // TODO: possibly undesired behavior, escapes argument though output should be unescaped and value is not passed as child
- $this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(output: "{value}")}'), 'Inline output argument');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
}
/*
* Escape children = false
* Escape output = false
+ * Escape arguments = false
*/
public function testWithEscapOutputFalseWithEscapeChildrenFalseWithoutContentOrOutputArguments()
{
+ // Nothing is escaped because all escaping is off.
$viewHelper = (new MutableTestViewHelper())->withEscapeOutput(false)->withEscapeChildren(false);
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test>{value}</test:test>'), 'Tag child variable');
@@ -205,25 +200,135 @@ public function testWithEscapOutputFalseWithEscapeChildrenFalseWithoutContentOrO
public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithContentArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withContentArgument()->withEscapeOutput(false)->withEscapeChildren(false);
+ // Child variable is not escaped because all escaping is off, including specific argument escaping.
+ $viewHelper = (new MutableTestViewHelper())->withContentArgument(false)->withEscapeOutput(false)->withEscapeChildren(false);
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
$this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test><div>{value}</div></test:test>'), 'Tag child variable with static HTML');
}
public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithOutputArgument()
{
- $viewHelper = (new MutableTestViewHelper())->withOutputArgument()->withEscapeOutput(false)->withEscapeChildren(false);
+ // Argument is not escaped because all escaping is off, including specific argument escaping.
+ $viewHelper = (new MutableTestViewHelper())->withOutputArgument(false)->withEscapeOutput(false)->withEscapeChildren(false);
$this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
$this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{f:if(condition: 1, then: value)}'), 'Inline output argument (f:if)');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ }
- // TODO: expected to break after introducing mandatory argument escaping on f:if then+else
- $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{f:if(condition: 1, then: value)}'), 'Inline output argument (f:if)');
+ /*
+ * Escape children = false
+ * Escape output = false
+ * Escape arguments = null
+ */
- // TODO: possibly undesired behavior, escapes argument though output should be unescaped and value is not passed as child
+ public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithEscapeArgumentNullWithContentArgument()
+ {
+ // All escaping is off, output will not be escaped
+ $viewHelper = (new MutableTestViewHelper())->withContentArgument(null)->withEscapeOutput(false)->withEscapeChildren(false);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test><div>{value}</div></test:test>'), 'Tag child variable with static HTML');
+ }
+
+ public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithEscapeArgumentNullWithOutputArgument()
+ {
+ // All escaping is off, output will not be escaped
+ $viewHelper = (new MutableTestViewHelper())->withOutputArgument(null)->withEscapeOutput(false)->withEscapeChildren(false);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
+ }
+
+ /*
+ * Escape children = false
+ * Escape output = false
+ * Escape arguments = true
+ */
+
+ public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithEscapeArgumentTrueWithContentArgument()
+ {
+ // Child variable is not escaped because both output and child escaping is off.
+ $viewHelper = (new MutableTestViewHelper())->withContentArgument(true)->withEscapeOutput(false)->withEscapeChildren(false);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
+ $this->assertSame(self::UNESCAPED_WRAPPED, $this->renderCode($viewHelper, '<test:test><div>{value}</div></test:test>'), 'Tag child variable with static HTML');
+ }
+
+ public function testWithEscapeOutputFalseWithEscapeChildrenFalseWithEscapeArgumentTrueWithOutputArgument()
+ {
+ // Output argument is escaped despite both escape-output and escape-children being OFF, because argument was explicitly requested to be escaped.
+ $viewHelper = (new MutableTestViewHelper())->withOutputArgument(true)->withEscapeOutput(false)->withEscapeChildren(false);
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test output="{value}" />'), 'Tag child variable');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(output: value)}'), 'Inline output argument');
+ $this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '<test:test output="<div>{value}</div>" />'), 'Tag with variable and static HTML');
$this->assertSame(self::ESCAPED_WRAPPED_STATIC_PROTECTED, $this->renderCode($viewHelper, '{test:test(output: "<div>{value}</div>")}'), 'Inline with static HTML');
}
+ /*
+ * Escape children = true
+ * Escape output = false
+ * Escape arguments = null
+ */
+
+ public function testEscapeContentArgumentWithEscapeChildrenTrueWithEscapeOutputOffEscapesArgument()
+ {
+ // Content argument is escaped because because escape-output is OFF but escape-children is ON and content argument is treated as child.
+ $viewHelper = (new MutableTestViewHelper())->withEscapeChildren(true)->withEscapeOutput(false)->withContentArgument(null);
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{value -> test:test()}'), 'Inline pass of variable');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '{test:test(content: value)}'), 'Inline with content argument');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test content="{value}" />'), 'Tag with content argument');
+ $this->assertSame(self::ESCAPED, $this->renderCode($viewHelper, '<test:test>{value}</test:test>'), 'Tag with child variable');
+ }
+
+ /*
+ * Disabling otherwise enabled escaping
+ */
+
+ public function testArgumentNotEscapedIfDisabledByFormatRawButNormallyWouldBeEscapedByOutputEscaping()
+ {
+ // Output is not escaped because VH is surrounded by f:format.raw, overriding escape-output, escape-children and escaping flag in ArgumentDefinition.
+ $viewHelper = (new MutableTestViewHelper())->withEscapeOutput(true)->withEscapeChildren(true)->withContentArgument(true);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<f:format.raw>{value -> test:test()}</f:format.raw>'), 'Inline pass of variable surrounded by format.raw');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test() -> f:format.raw()}'), 'Inline pass of variable chained with format.raw');
+ }
+
+ public function testArgumentNotEscapedEvenIfArgumentRequestedEscapedBecauseChainingWithFormatRawOverridesArgumentEscaping()
+ {
+ // Content argument is not escaped, despite flag in ArgumentDefinition, because argument is chained with f:format.raw which overrides argument escaping.
+ $viewHelper = (new MutableTestViewHelper())->withEscapeOutput(false)->withEscapeChildren(false)->withContentArgument(true);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<test:test content="{value -> f:format.raw()}" />'), 'Tag with argument chained with format.raw');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{test:test(content: "{value -> f:format.raw()}")}'), 'Inline with argument chained with format.raw');
+ }
+
+ public function testArgumentNotEscapedIfDisabledByFormatRawButNormallyWouldBeEscapedByArgumentEscaping()
+ {
+ // Child is not escaped because VH is surrounded by f:format.raw, overriding escaping flag in ArgumentDefinition.
+ $viewHelper = (new MutableTestViewHelper())->withEscapeOutput(false)->withEscapeChildren(false);
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '<f:format.raw>{value -> test:test()}</f:format.raw>'), 'Inline pass of variable surrounded by format.raw');
+ $this->assertSame(self::UNESCAPED, $this->renderCode($viewHelper, '{value -> test:test() -> f:format.raw()}'), 'Inline pass of variable chained with format.raw');
+ }
+
+ /*
+ * TagBasedViewHelper attribute escaping
+ */
+
+ public function testTagBasedViewHelperEscapesAttributes()
+ {
+ // Tag ViewHelper attributes are always escaped; the only way to disable this escaping is for the VH to manually add the attribute and explicitly disable conversion of special HTML chars.
+ $viewHelper = new TagBasedTestViewHelper();
+ $this->assertSame('<div class="' . self::ESCAPED . '" />', $this->renderCode($viewHelper, '<test:test class="{value}" />'), 'Tag attribute is escaped');
+ $this->assertSame('<div data-foo="' . self::ESCAPED . '" />', $this->renderCode($viewHelper, '<test:test data="{foo: value}" />'), 'Tag data attribute values are escaped');
+ $this->assertSame('<div foo="' . self::ESCAPED . '" />', $this->renderCode($viewHelper, '<test:test additionalAttributes="{foo: value}" />'), 'Tag additional attributes values are escaped');
+ $this->assertSame('<div data->' . self::ESCAPED . '<="1" />', $this->renderCode($viewHelper, '<test:test data=\'{"><script>alert(1)</script><": 1}\' />'), 'Tag data attribute keys are escaped');
+ $this->assertSame('<div >' . self::ESCAPED . '<="1" />', $this->renderCode($viewHelper, '<test:test additionalAttributes=\'{"><script>alert(1)</script><": 1}\' />'), 'Tag additional attributes keys are escaped');
+
+ // Disabled: bug detected, handleAdditionalArguments on AbstractTagBasedViewHelper does assign the tag attribute, but following this call,
+ // the initialize() method is called which resets the TagBuilder and in turn removes the data- prefixed attributes which are then not re-assigned.
+ // Regression caused by https://github.com/TYPO3/Fluid/pull/419.
+ //$this->assertSame('<div data-foo="' . self::ESCAPED . '" />', $this->renderCode($viewHelper, '<test:test data-foo="{value}" />'), 'Tag unregistered data attribute is escaped');
+ }
+
/**
* @return array
*/
@@ -279,11 +384,11 @@ public function getTemplateCodeFixturesAndExpectations()
['<strong>Bla</strong>'],
['<strong>Bla</strong>'],
],
- 'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does encode variable value (encoded before passed to VH)' => [
+ 'EscapeChildrenEnabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does not encode variable value' => [
'{test:escapeChildrenEnabledAndEscapeOutputDisabled(content: \'{settings.test}\')}',
$this->variables,
- ['<strong>Bla</strong>'],
['<strong>Bla</strong>'],
+ ['<strong>Bla</strong>'],
],
'EscapeChildrenEnabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and children rendering, does not encode variable value' => [
'<test:escapeChildrenEnabledAndEscapeOutputDisabled content="{settings.test -> test:escapeChildrenEnabledAndEscapeOutputDisabled()}" />',
@@ -327,11 +432,11 @@ public function getTemplateCodeFixturesAndExpectations()
['<strong>Bla</strong>'],
['<strong>Bla</strong>'],
],
- 'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does encode variable value (encoded before passed to VH)' => [
+ 'EscapeChildrenDisabledAndEscapeOutputDisabled: Inline syntax with argument in quotes, does not encode variable value' => [
'{test:escapeChildrenDisabledAndEscapeOutputDisabled(content: \'{settings.test}\')}',
$this->variables,
- ['<strong>Bla</strong>'],
['<strong>Bla</strong>'],
+ ['<strong>Bla</strong>'],
],
'EscapeChildrenDisabledAndEscapeOutputDisabled: Tag syntax with nested inline syntax and children rendering, does not encode variable value' => [
'<test:escapeChildrenDisabledAndEscapeOutputDisabled content="{settings.test -> test:escapeChildrenDisabledAndEscapeOutputDisabled()}" />',
diff --git a/tests/Functional/Fixtures/ViewHelpers/MutableTestViewHelper.php b/tests/Functional/Fixtures/ViewHelpers/MutableTestViewHelper.php
index c5bf98144..332c9a14a 100644
--- a/tests/Functional/Fixtures/ViewHelpers/MutableTestViewHelper.php
+++ b/tests/Functional/Fixtures/ViewHelpers/MutableTestViewHelper.php
@@ -24,16 +24,16 @@ public function setEscapeOutput($escapeOutput): void
$this->escapeOutput = $escapeOutput;
}
- public function registerArgument($name, $type, $description, $required = false, $defaultValue = null)
+ public function registerArgument($name, $type, $description, $required = false, $defaultValue = null, $escaped = null)
{
- return parent::registerArgument($name, $type, $description, $required, $defaultValue);
+ return parent::registerArgument($name, $type, $description, $required, $defaultValue, $escaped);
}
public function withContentArgument($escaped = null): self
{
// TODO: set escaping behavior if $escaped !== null
$clone = clone $this;
- $clone->registerArgument('content', 'string', 'Content argument');
+ $clone->registerArgument('content', 'string', 'Content argument', false, null, $escaped);
return $clone;
}
@@ -41,7 +41,7 @@ public function withOutputArgument($escaped = null): self
{
// TODO: set escaping behavior if $escaped !== null
$clone = clone $this;
- $clone->registerArgument('output', 'string', 'Content argument', true);
+ $clone->registerArgument('output', 'string', 'Content argument', true, null, $escaped);
return $clone;
}
@@ -59,6 +59,11 @@ public function withEscapeOutput($escapeOutput): self
return $clone;
}
+ public function resolveContentArgumentName()
+ {
+ return 'content';
+ }
+
public function render()
{
$argumentDefinitions = $this->prepareArguments();
diff --git a/tests/Functional/Fixtures/ViewHelpers/TagBasedTestViewHelper.php b/tests/Functional/Fixtures/ViewHelpers/TagBasedTestViewHelper.php
new file mode 100644
index 000000000..ddd11829b
--- /dev/null
+++ b/tests/Functional/Fixtures/ViewHelpers/TagBasedTestViewHelper.php
@@ -0,0 +1,17 @@
+<?php
+namespace TYPO3Fluid\Fluid\Tests\Functional\Fixtures\ViewHelpers;
+
+use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
+
+class TagBasedTestViewHelper extends AbstractTagBasedViewHelper
+{
+ public function prepareArguments()
+ {
+ // Override to avoid the static cache of registered ViewHelper arguments; will always return
+ // only those arguments that are registered in this particular instance.
+ $this->argumentDefinitions = [];
+ $this->registerUniversalTagAttributes();
+ $this->initializeArguments();
+ return $this->argumentDefinitions;
+ }
+}
\ No newline at end of file
diff --git a/tests/Unit/Core/Parser/TemplateParserTest.php b/tests/Unit/Core/Parser/TemplateParserTest.php
index 008f8efda..fd4a0ce77 100644
--- a/tests/Unit/Core/Parser/TemplateParserTest.php
+++ b/tests/Unit/Core/Parser/TemplateParserTest.php
@@ -450,7 +450,7 @@ public function objectAccessorHandlerCallsInitializeViewHelperAndAddItToStackIfV
);
$templateParser->setRenderingContext(new RenderingContextFixture());
$templateParser->expects($this->at(0))->method('recursiveArrayHandler')
- ->with('arguments: {0: \'foo\'}')->will($this->returnValue(['arguments' => ['foo']]));
+ ->with($mockState, 'arguments: {0: \'foo\'}')->will($this->returnValue(['arguments' => ['foo']]));
$templateParser->expects($this->at(1))->method('initializeViewHelperAndAddItToStack')
->with($mockState, 'f', 'format.printf', ['arguments' => ['foo']])->will($this->returnValue(true));
$templateParser->expects($this->at(2))->method('initializeViewHelperAndAddItToStack')
@@ -1004,6 +1004,7 @@ public function dataProviderRecursiveArrayHandler()
*/
public function testRecursiveArrayHandler($string, $expected)
{
+ $state = new ParsingState();
$resolver = $this->getMock(ViewHelperResolver::class, ['isNamespaceIgnored']);
$resolver->expects($this->any())->method('isNamespaceIgnored')->willReturn(true);
$context = new RenderingContextFixture();
@@ -1013,7 +1014,7 @@ public function testRecursiveArrayHandler($string, $expected)
$templateParser->setRenderingContext($context);
$method = new \ReflectionMethod($templateParser, 'recursiveArrayHandler');
$method->setAccessible(true);
- $result = $method->invokeArgs($templateParser, [$string]);
+ $result = $method->invokeArgs($templateParser, [$state, $string]);
$this->assertEquals($expected, $result);
}
|