Bug #86425
closedNested SwitchViewHelpers inside RenderViewHelpers does not break after rendering case
0%
Description
Setup:
- Create a Fluid Template containing a simple f:switch:
<f:switch expression="1"> <f:case value="1"> Case 1<br> <f:render partial="Test" arguments="{val: 1}" /> </f:case> <f:defaultCase> Default 1<br> </f:defaultCase> </f:switch>
- Create Partial Test:
<f:switch expression="{val}"> <f:case value="2"> Case 2 </f:case> <f:defaultCase> Default 2 <f:render partial="Test" arguments="{val: 2}" /> </f:defaultCase> </f:switch>
Expected output:
Case 1 Default 2 Case 2
Actual output:
Default 1
This happens because in the ViewHelperVariableContainer the `break` variable of the OriginalSwitchViewHelper is getting overridden.
I have tried the following permutations of ViewHelpers. Note: Render2 is another partial called Test2.
No Errors:
Switch -> Case -> Switch -> Case
Switch -> Case -> Switch -> Default
Switch -> Default -> Switch -> Case
Switch -> Default -> Switch -> Default
Switch -> Case -> Switch -> Case -> Switch -> Case
Switch -> Case -> Switch -> Case -> Switch -> Default
Switch -> Case -> Render -> Switch -> Case
Switch -> Case -> Render -> Switch -> Default
Switch -> Default -> Render -> Switch -> Case
Switch -> Default -> Render -> Switch -> Default
Switch -> Case -> Render -> Render2 -> Switch -> Case
Switch -> Case -> Render -> Render2 -> Switch -> Default
Switch -> Case -> Render -> Render -> Case
Switch -> Case -> Render -> Render -> Default
Switch -> Case -> Render -> Switch -> Case -> Render -> Switch -> Case
Switch -> Case -> Render -> Switch -> Case -> Render -> Switch -> Default
Switch -> Case -> Render -> Switch -> Case -> Render2 -> Switch -> Case
Switch -> Case -> Render -> Switch -> Case -> Render2 -> Switch -> Default
Switch -> Case -> Render -> Switch -> Default -> Render2 -> Switch -> Case
Switch -> Case -> Render -> Switch -> Default -> Render2 -> Switch -> Default
The following parmutations produce the error:
Switch -> Case -> Render -> Switch -> Default -> Render -> Switch -> Case
Switch -> Case -> Render -> Switch -> Default -> Render -> Switch -> Default
Now the funny part begins. This permutations produces the expected output:
Switch -> Case -> Render -> If -> Then -> Switch -> Default -> Render -> If -> Else -> Switch -> Case
Here is the fluid content for partial 'Test' for this permutation:
<f:if condition="{val} != 2">
<f:then>
<f:switch expression="{val}">
<f:case value="2">
Case 2
</f:case>
<f:defaultCase>
Default 2
<f:render partial="Test" arguments="{val: 2}" />
</f:defaultCase>
</f:switch>
</f:then>
<f:else>
<f:switch expression="1">
<f:case value="1">
Case 3
</f:case>
<f:defaultCase>Default 3</f:defaultCase>
</f:switch>
</f:else>
</f:if>
But the following variant prduces the error:
Switch -> Case -> Render -> If -> Then -> Switch -> Default -> Render -> If -> Then -> Switch -> Case
<f:if condition="{val} != 2">
<f:then>
<f:switch expression="{val}">
<f:case value="3">
Case 2
</f:case>
<f:defaultCase>
Default 2
<f:render partial="Test" arguments="{val: 3}" />
</f:defaultCase>
</f:switch>
</f:then>
<f:else>
<f:switch expression="1">
<f:case value="1">
Case 3
</f:case>
<f:defaultCase>Default 3</f:defaultCase>
</f:switch>
</f:else>
</f:if>
It seems that it has something to do with equal instances of the switch ViewHelper. So I tried the following code inside a partial (the template only renders the partial with val=1, without any other code in it):
Render -> Switch -> Case -> Render -> Switch -> Default -> Render -> Switch -> Case
<f:switch expression="{val}">
<f:case value="1">
Case 1
<f:render partial="Test" arguments="{val: 3}" />
</f:case>
<f:case value="2">
Case 2
</f:case>
<f:defaultCase>
Default 1
<f:render partial="Test" arguments="{val: 2}" />
</f:defaultCase>
</f:switch>
Expected output:
Case 1 Default 1 Case 2
Actual output:
Default 1 Case 2
Again, this permutations work:
Render > Switch -> Case -> Render> Switch -> Default
Render -> Switch -> Case -> Render -> Switch -> Case -> Render -> Switch -> Default
Adding another Rendering with switch/case to the non working example produces the expected output again:
Render -> Switch -> Case -> Render -> Switch -> Default -> Render -> Switch -> Case -> Switch -> Case
<f:switch expression="{val}">
<f:case value="1">
Case 1
<f:render partial="Test" arguments="{val: 3}" />
</f:case>
<f:case value="2">
Case 2
<f:render partial="Test" arguments="{val: 4}" />
</f:case>
<f:case value="4">
Case 3
</f:case>
<f:defaultCase>
Default 1
<f:render partial="Test" arguments="{val: 2}" />
</f:defaultCase>
</f:switch>
Expected and actual output:
Case 1 Default 1 Case 2 Case 3