@@ -79,6 +79,10 @@ pub fn expand_partial<'reg: 'rc, 'rc>(
7979 let mut block = BlockContext :: new ( ) ;
8080 * block. base_path_mut ( ) = base_path. to_vec ( ) ;
8181 block_created = true ;
82+
83+ // clear blocks to prevent block params from parent
84+ // template to be leaked into partials
85+ local_rc. clear_blocks ( ) ;
8286 local_rc. push_block ( block) ;
8387 } else if !d. hash ( ) . is_empty ( ) {
8488 let mut block = BlockContext :: new ( ) ;
@@ -93,8 +97,14 @@ pub fn expand_partial<'reg: 'rc, 'rc>(
9397 local_rc. evaluate2 ( ctx, & Path :: current ( ) ) ?. as_json ( ) ,
9498 & hash_ctx,
9599 ) ;
100+
96101 block. set_base_value ( merged_context) ;
97102 block_created = true ;
103+
104+ // clear blocks to prevent block params from parent
105+ // template to be leaked into partials
106+ // see `test_partial_context_issue_495` for the case.
107+ local_rc. clear_blocks ( ) ;
98108 local_rc. push_block ( block) ;
99109 }
100110
@@ -491,4 +501,45 @@ name: there
491501 . unwrap ( ) ;
492502 assert_eq ! ( ":(\n " , r2) ;
493503 }
504+
505+ #[ test]
506+ fn test_partial_context_issue_495 ( ) {
507+ let mut hb = Registry :: new ( ) ;
508+ hb. register_template_string (
509+ "t1" ,
510+ r#"{{~#*inline "displayName"~}}
511+ Template:{{name}}
512+ {{/inline}}
513+ {{#each data as |name|}}
514+ Name:{{name}}
515+ {{>displayName name="aaaa"}}
516+ {{/each}}"# ,
517+ )
518+ . unwrap ( ) ;
519+
520+ hb. register_template_string (
521+ "t1" ,
522+ r#"{{~#*inline "displayName"~}}
523+ Template:{{this}}
524+ {{/inline}}
525+ {{#each data as |name|}}
526+ Name:{{name}}
527+ {{>displayName}}
528+ {{/each}}"# ,
529+ )
530+ . unwrap ( ) ;
531+
532+ let data = json ! ( {
533+ "data" : [ "hudel" , "test" ]
534+ } ) ;
535+
536+ assert_eq ! (
537+ r#"Name:hudel
538+ Template:hudel
539+ Name:test
540+ Template:test
541+ "# ,
542+ hb. render( "t1" , & data) . unwrap( )
543+ ) ;
544+ }
494545}
0 commit comments