@@ -489,7 +489,7 @@ protected function objectAccessorHandler(ParsingState $state, $objectAccessorStr
489
489
}
490
490
$ viewHelper = $ viewHelperResolver ->createViewHelperInstance ($ singleMatch ['NamespaceIdentifier ' ], $ singleMatch ['MethodIdentifier ' ]);
491
491
if (strlen ($ singleMatch ['ViewHelperArguments ' ]) > 0 ) {
492
- $ arguments = $ this ->recursiveArrayHandler ($ singleMatch ['ViewHelperArguments ' ], $ viewHelper );
492
+ $ arguments = $ this ->recursiveArrayHandler ($ state , $ singleMatch ['ViewHelperArguments ' ], $ viewHelper );
493
493
} else {
494
494
$ arguments = [];
495
495
}
@@ -563,28 +563,43 @@ protected function parseArguments($argumentsString, ViewHelperInterface $viewHel
563
563
$ undeclaredArguments = [];
564
564
$ matches = [];
565
565
if (preg_match_all (Patterns::$ SPLIT_PATTERN_TAGARGUMENTS , $ argumentsString , $ matches , PREG_SET_ORDER ) > 0 ) {
566
- $ escapingEnabledBackup = $ this ->escapingEnabled ;
567
- $ this ->escapingEnabled = false ;
568
566
foreach ($ matches as $ singleMatch ) {
569
567
$ argument = $ singleMatch ['Argument ' ];
570
568
$ value = $ this ->unquoteString ($ singleMatch ['ValueQuoted ' ]);
571
- $ argumentsObjectTree [ $ argument ] = $ this ->buildArgumentObjectTree ( $ value ) ;
569
+ $ escapingEnabledBackup = $ this ->escapingEnabled ;
572
570
if (isset ($ argumentDefinitions [$ argument ])) {
573
571
$ argumentDefinition = $ argumentDefinitions [$ argument ];
574
- if ($ argumentDefinition ->getType () === 'boolean ' || $ argumentDefinition ->getType () === 'bool ' ) {
572
+ $ this ->escapingEnabled = $ this ->escapingEnabled && $ this ->isArgumentEscaped ($ viewHelper , $ argumentDefinition );
573
+ $ isBoolean = $ argumentDefinition ->getType () === 'boolean ' || $ argumentDefinition ->getType () === 'bool ' ;
574
+ $ argumentsObjectTree [$ argument ] = $ this ->buildArgumentObjectTree ($ value );
575
+ if ($ isBoolean ) {
575
576
$ argumentsObjectTree [$ argument ] = new BooleanNode ($ argumentsObjectTree [$ argument ]);
576
577
}
577
578
} else {
578
- $ undeclaredArguments [$ argument ] = $ argumentsObjectTree [$ argument ];
579
+ $ this ->escapingEnabled = false ;
580
+ $ undeclaredArguments [$ argument ] = $ this ->buildArgumentObjectTree ($ value );
579
581
}
582
+ $ this ->escapingEnabled = $ escapingEnabledBackup ;
580
583
}
581
- $ this ->escapingEnabled = $ escapingEnabledBackup ;
582
584
}
583
585
$ this ->abortIfRequiredArgumentsAreMissing ($ argumentDefinitions , $ argumentsObjectTree );
584
586
$ viewHelper ->validateAdditionalArguments ($ undeclaredArguments );
585
587
return $ argumentsObjectTree + $ undeclaredArguments ;
586
588
}
587
589
590
+ protected function isArgumentEscaped (ViewHelperInterface $ viewHelper , ArgumentDefinition $ argumentDefinition = null )
591
+ {
592
+ $ hasDefinition = $ argumentDefinition instanceof ArgumentDefinition;
593
+ $ isBoolean = $ hasDefinition && ($ argumentDefinition ->getType () === 'boolean ' || $ argumentDefinition ->getType () === 'bool ' );
594
+ $ escapingEnabled = $ this ->configuration ->isViewHelperArgumentEscapingEnabled ();
595
+ $ isArgumentEscaped = $ hasDefinition && $ argumentDefinition ->getEscape () === true ;
596
+ $ isContentArgument = $ hasDefinition && method_exists ($ viewHelper , 'resolveContentArgumentName ' ) && $ argumentDefinition ->getName () === $ viewHelper ->resolveContentArgumentName ();
597
+ if ($ isContentArgument ) {
598
+ return !$ isBoolean && ($ viewHelper ->isChildrenEscapingEnabled () || $ isArgumentEscaped );
599
+ }
600
+ return !$ isBoolean && $ escapingEnabled && $ isArgumentEscaped ;
601
+ }
602
+
588
603
/**
589
604
* Build up an argument object tree for the string in $argumentString.
590
605
* This builds up the tree for a single argument value.
@@ -664,7 +679,7 @@ protected function textAndShorthandSyntaxHandler(ParsingState $state, $text, $co
664
679
&& preg_match (Patterns::$ SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS , $ section , $ matchedVariables ) > 0
665
680
) {
666
681
// We only match arrays if we are INSIDE viewhelper arguments
667
- $ this ->arrayHandler ($ state , $ this ->recursiveArrayHandler ($ matchedVariables ['Array ' ]));
682
+ $ this ->arrayHandler ($ state , $ this ->recursiveArrayHandler ($ state , $ matchedVariables ['Array ' ]));
668
683
} else {
669
684
// We ask custom ExpressionNode instances from ViewHelperResolver
670
685
// if any match our expression:
@@ -737,12 +752,13 @@ protected function arrayHandler(ParsingState $state, $arrayText)
737
752
* - Variables
738
753
* - sub-arrays
739
754
*
755
+ * @param ParsingState $state
740
756
* @param string $arrayText Array text
741
757
* @param ViewHelperInterface|null $viewHelper ViewHelper instance - passed only if the array is a collection of arguments for an inline ViewHelper
742
758
* @return NodeInterface[] the array node built up
743
759
* @throws Exception
744
760
*/
745
- protected function recursiveArrayHandler ($ arrayText , ViewHelperInterface $ viewHelper = null )
761
+ protected function recursiveArrayHandler (ParsingState $ state , $ arrayText , ViewHelperInterface $ viewHelper = null )
746
762
{
747
763
$ undeclaredArguments = [];
748
764
$ argumentDefinitions = [];
@@ -755,14 +771,25 @@ protected function recursiveArrayHandler($arrayText, ViewHelperInterface $viewHe
755
771
foreach ($ matches as $ singleMatch ) {
756
772
$ arrayKey = $ this ->unquoteString ($ singleMatch ['Key ' ]);
757
773
$ assignInto = &$ arrayToBuild ;
758
- if (!isset ($ argumentDefinitions [$ arrayKey ])) {
774
+ $ isBoolean = false ;
775
+ $ argumentDefinition = null ;
776
+ if (isset ($ argumentDefinitions [$ arrayKey ])) {
777
+ $ argumentDefinition = $ argumentDefinitions [$ arrayKey ];
778
+ $ isBoolean = $ argumentDefinitions [$ arrayKey ]->getType () === 'boolean ' || $ argumentDefinitions [$ arrayKey ]->getType () === 'bool ' ;
779
+ } else {
759
780
$ assignInto = &$ undeclaredArguments ;
760
781
}
761
782
783
+ $ escapingEnabledBackup = $ this ->escapingEnabled ;
784
+ $ this ->escapingEnabled = $ this ->escapingEnabled && $ viewHelper instanceof ViewHelperInterface && $ this ->isArgumentEscaped ($ viewHelper , $ argumentDefinition );
785
+
762
786
if (array_key_exists ('Subarray ' , $ singleMatch ) && !empty ($ singleMatch ['Subarray ' ])) {
763
- $ assignInto [$ arrayKey ] = new ArrayNode ($ this ->recursiveArrayHandler ($ singleMatch ['Subarray ' ]));
787
+ $ assignInto [$ arrayKey ] = new ArrayNode ($ this ->recursiveArrayHandler ($ state , $ singleMatch ['Subarray ' ]));
764
788
} elseif (!empty ($ singleMatch ['VariableIdentifier ' ])) {
765
789
$ assignInto [$ arrayKey ] = new ObjectAccessorNode ($ singleMatch ['VariableIdentifier ' ]);
790
+ if ($ viewHelper instanceof ViewHelperInterface && !$ isBoolean ) {
791
+ $ this ->callInterceptor ($ assignInto [$ arrayKey ], InterceptorInterface::INTERCEPT_OBJECTACCESSOR , $ state );
792
+ }
766
793
} elseif (array_key_exists ('Number ' , $ singleMatch ) && (!empty ($ singleMatch ['Number ' ]) || $ singleMatch ['Number ' ] === '0 ' )) {
767
794
// Note: this method of casting picks "int" when value is a natural number and "float" if any decimals are found. See also NumericNode.
768
795
$ assignInto [$ arrayKey ] = $ singleMatch ['Number ' ] + 0 ;
@@ -771,9 +798,11 @@ protected function recursiveArrayHandler($arrayText, ViewHelperInterface $viewHe
771
798
$ assignInto [$ arrayKey ] = $ this ->buildArgumentObjectTree ($ argumentString );
772
799
}
773
800
774
- if (isset ( $ argumentDefinitions [ $ arrayKey ]) && ( $ argumentDefinitions [ $ arrayKey ]-> getType () === ' boolean ' || $ argumentDefinitions [ $ arrayKey ]-> getType () === ' bool ' ) ) {
801
+ if ($ isBoolean ) {
775
802
$ assignInto [$ arrayKey ] = new BooleanNode ($ assignInto [$ arrayKey ]);
776
803
}
804
+
805
+ $ this ->escapingEnabled = $ escapingEnabledBackup ;
777
806
}
778
807
}
779
808
if ($ viewHelper instanceof ViewHelperInterface) {
0 commit comments