@@ -192,7 +192,6 @@ public override void OnRender( ILavaRenderContext context, TextWriter result )
192192 // Parameters declared on child elements can be referenced in the shortcode template as <childElementName>.<paramName>.
193193
194194 string residualMarkup = string . Empty ;
195- var keysToCleanup = new List < string > ( ) ;
196195
197196 if ( parms [ "processchilditems" ] . ToString ( ) . AsBoolean ( ) )
198197 {
@@ -210,7 +209,6 @@ public override void OnRender( ILavaRenderContext context, TextWriter result )
210209 // Add the collections of child to the set of parameters that will be passed to the shortcode template.
211210 foreach ( var item in childElements )
212211 {
213- keysToCleanup . Add ( item . Key ) ;
214212 parms . AddOrReplace ( item . Key , item . Value ) ;
215213 }
216214 }
@@ -277,15 +275,11 @@ public override void OnRender( ILavaRenderContext context, TextWriter result )
277275 }
278276 }
279277
280- // This is a partial fix for issue #6470. Due to variable leakage between
281- // shortcode executions, some shortcodes were failing if you used multiple
282- // instances of the same shortcode on a page with different parameters.
283- // In the future we will fix the EnterChildScope() implementation to
284- // completely isolate the merge fields of the child scope from the parent.
285- var savedMergeFields = SaveOriginalMergeFields ( context , keysToCleanup ) ;
286-
287- // Render the shortcode template in a child scope that includes the shortcode parameters.
288- context . EnterChildScope ( ) ;
278+ var isIsolatedScope = _shortcode . ShortcodeScopeBehavior == Enums . Cms . ShortcodeScopeBehavior . Isolated ;
279+ if ( isIsolatedScope )
280+ {
281+ context . EnterChildScope ( ) ;
282+ }
289283
290284 LavaRenderResult results ;
291285 try
@@ -312,11 +306,12 @@ public override void OnRender( ILavaRenderContext context, TextWriter result )
312306 }
313307 finally
314308 {
315- context . ExitChildScope ( ) ;
309+ if ( isIsolatedScope )
310+ {
311+ context . ExitChildScope ( ) ;
312+ }
316313 }
317314
318- RestoreOriginalMergeFields ( context , savedMergeFields ) ;
319-
320315 // Reset the original parameters in the context
321316 context . SetMergeField ( "blockContent" , originalBlockContent ) ;
322317 context . SetMergeField ( "RecursionDepth" , originalRecursionDepth ) ;
@@ -513,40 +508,5 @@ private void AssertShortcodeIsInitialized()
513508 throw new Exception ( $ "Shortcode configuration error. \" { _tagName } \" is not initialized." ) ;
514509 }
515510 }
516-
517- /// <summary>
518- /// Saves the current merge field values for the specified keys.
519- /// </summary>
520- /// <param name="context">The lava context to get the values from.</param>
521- /// <param name="keys">The keys whose values will be returned.</param>
522- /// <returns>A dictionary of keys and values that can be later restored.</returns>
523- private Dictionary < string , object > SaveOriginalMergeFields ( ILavaRenderContext context , IEnumerable < string > keys )
524- {
525- var saved = new Dictionary < string , object > ( ) ;
526-
527- foreach ( var key in keys )
528- {
529- saved [ key ] = context . GetMergeField ( key , null ) ;
530- }
531-
532- return saved ;
533- }
534-
535- /// <summary>
536- /// Restores the saved merge fields to the specified context. This
537- /// is used to make a best effor to reset the context to its original
538- /// state after rendering a shortcode. The shortcode will have modified
539- /// the merge fields in order to pass the parameters to the shortcode
540- /// template. We attempt to undo that.
541- /// </summary>
542- /// <param name="context">The lava context to restore the values on.</param>
543- /// <param name="savedMergeFields">The saved merge fields.</param>
544- private void RestoreOriginalMergeFields ( ILavaRenderContext context , Dictionary < string , object > savedMergeFields )
545- {
546- foreach ( var kvp in savedMergeFields )
547- {
548- context . SetMergeField ( kvp . Key , kvp . Value ) ;
549- }
550- }
551511 }
552512}
0 commit comments