@@ -52,17 +52,24 @@ pub fn expand_partial<'reg: 'rc, 'rc>(
5252 return Err ( RenderError :: new ( "Cannot include self in >" ) ) ;
5353 }
5454
55- // if tname == PARTIAL_BLOCK
5655 let partial = find_partial ( rc, r, d, tname) ?;
5756
5857 if let Some ( t) = partial {
5958 // clone to avoid lifetime issue
6059 // FIXME refactor this to avoid
6160 let mut local_rc = rc. clone ( ) ;
61+
62+ // if tname == PARTIAL_BLOCK
6263 let is_partial_block = tname == PARTIAL_BLOCK ;
6364
65+ // add partial block depth there are consecutive partial
66+ // blocks in the stack.
6467 if is_partial_block {
6568 local_rc. inc_partial_block_depth ( ) ;
69+ } else {
70+ // depth cannot be lower than 0, which is guaranted in the
71+ // `dec_partial_block_depth` method
72+ local_rc. dec_partial_block_depth ( ) ;
6673 }
6774
6875 let mut block_created = false ;
@@ -103,10 +110,6 @@ pub fn expand_partial<'reg: 'rc, 'rc>(
103110 local_rc. pop_block ( ) ;
104111 }
105112
106- if is_partial_block {
107- local_rc. dec_partial_block_depth ( ) ;
108- }
109-
110113 if d. template ( ) . is_some ( ) {
111114 local_rc. pop_partial_block ( ) ;
112115 }
@@ -297,7 +300,7 @@ mod test {
297300 }
298301
299302 #[ test]
300- fn test_nested_partials ( ) {
303+ fn test_nested_partial_block ( ) {
301304 let mut handlebars = Registry :: new ( ) ;
302305 let template1 = "<outer>{{> @partial-block }}</outer>" ;
303306 let template2 = "{{#> t1 }}<inner>{{> @partial-block }}</inner>{{/ t1 }}" ;
@@ -451,4 +454,41 @@ name: there
451454"#
452455 ) ;
453456 }
457+
458+ #[ test]
459+ fn test_nested_partials ( ) {
460+ let mut hb = Registry :: new ( ) ;
461+ hb. register_template_string ( "partial" , "{{> @partial-block}}" )
462+ . unwrap ( ) ;
463+ hb. register_template_string (
464+ "index" ,
465+ r#"{{#>partial}}
466+ Yo
467+ {{#>partial}}
468+ Yo 2
469+ {{/partial}}
470+ {{/partial}}"# ,
471+ )
472+ . unwrap ( ) ;
473+ assert_eq ! (
474+ r#" Yo
475+ Yo 2
476+ "# ,
477+ hb. render( "index" , & ( ) ) . unwrap( )
478+ ) ;
479+
480+ hb. register_template_string ( "partial2" , "{{> @partial-block}}" )
481+ . unwrap ( ) ;
482+ let r2 = hb
483+ . render_template (
484+ r#"{{#> partial}}
485+ {{#> partial2}}
486+ :(
487+ {{/partial2}}
488+ {{/partial}}"# ,
489+ & ( ) ,
490+ )
491+ . unwrap ( ) ;
492+ assert_eq ! ( ":(\n " , r2) ;
493+ }
454494}
0 commit comments