From 6c2d074f14a9548202dfb3706c8b6af61fed7227 Mon Sep 17 00:00:00 2001 From: Sahab Yazdani Date: Wed, 27 Apr 2011 15:05:44 -0400 Subject: [PATCH] Fix change delimiter inside section --- mustache.js | 15 ++++++++++----- test/unit.js | 14 +++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mustache.js b/mustache.js index a679435..247843e 100644 --- a/mustache.js +++ b/mustache.js @@ -482,17 +482,22 @@ var Mustache = (function(undefined) { throw new Error('Malformed change delimiter token: ' + token); } - var context = create_compiler_state( + var new_state = create_compiler_state( state.tokens.slice(state.cursor+1).join('') , state.partials , matches[1] , matches[2]); - context.code = state.code; - context.send_code_func = state.send_code_func; - + new_state.code = state.code; + new_state.send_code_func = state.send_code_func; + new_state.parser = state.parser; + new_state.section = state.section; + if (new_state.section) { + new_state.section.template_buffer.push(token); + } + state.cursor = state.tokens.length; // finish off this level - compile(context, true); + compile(new_state, true); } function begin_section(state, token, mark) { diff --git a/test/unit.js b/test/unit.js index c181313..5fae8cf 100644 --- a/test/unit.js +++ b/test/unit.js @@ -399,6 +399,18 @@ test("'=' (Set Delimiter)", function() { '*\nIt worked the first time.\n* And it worked the second time.\n\n* Then, surprisingly, it worked the third time.\n\n* Fourth time also fine!.', 'Simple Set Delimiter' ); + + equals( + Mustache.to_html( + '{{#noData}}{{=~~ ~~=}}Set Change Delimiter ~~data~~ ~~={{ }}=~~{{/noData}}' + , { + noData: true + , data: false + } + , {} + ) + , 'Set Change Delimiter false ' + , 'Change Delimiter inside Section'); }); test("'!' (Comments)", function() { @@ -619,4 +631,4 @@ test("Regression Suite", function() { , 'foobar' , 'Nested Sections with the same name' ); -}); +}); \ No newline at end of file