@@ -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 }}" ;
@@ -453,7 +456,7 @@ name: there
453456 }
454457
455458 #[ test]
456- fn test_nested_partial ( ) {
459+ fn test_nested_partials ( ) {
457460 let mut hb = Registry :: new ( ) ;
458461 hb. register_template_string ( "partial" , "{{> @partial-block}}" )
459462 . unwrap ( ) ;
@@ -469,7 +472,8 @@ name: there
469472 . unwrap ( ) ;
470473 assert_eq ! (
471474 r#" Yo
472- Yo 2"# ,
475+ Yo 2
476+ "# ,
473477 hb. render( "index" , & ( ) ) . unwrap( )
474478 ) ;
475479 }
0 commit comments