From 6a0ce24857be1d7f0cc37c327afb89c7fadd53e5 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Wed, 12 Nov 2014 09:11:12 -0800 Subject: [PATCH] fix one time mustache parsing --- src/TemplateBinding.js | 10 +++++++++- test/tests.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/TemplateBinding.js b/src/TemplateBinding.js index 374561a..c2e8d1c 100644 --- a/src/TemplateBinding.js +++ b/src/TemplateBinding.js @@ -670,7 +670,15 @@ terminator = ']]'; } - endIndex = startIndex < 0 ? -1 : s.indexOf(terminator, startIndex + 2); + if (startIndex >= 0) { + endIndex = s.indexOf(terminator, startIndex + 2); + // Handle this case [[foo['bar']]] and others like it. + while (s.length > endIndex + 2 && s[endIndex + 2] == terminator[0]) { + endIndex++; + } + } else { + endIndex = -1; + } if (endIndex < 0) { if (!tokens) diff --git a/test/tests.js b/test/tests.js index f450db4..ed1f31d 100644 --- a/test/tests.js +++ b/test/tests.js @@ -634,6 +634,22 @@ suite('Template Instantiation', function() { }); }); + test('OneTime - list/map', function(done) { + var div = createTestHtml( + ''); + var template = div.firstChild; + var m = { foo: {'bar': 'baz'}, zap: ['zip'] }; + template.model = m; + + then(function() { + assert.strictEqual(2, div.childNodes.length); + assert.strictEqual('baz:zip', div.lastChild.getAttribute('foo')); + done(); + }); + }); + test('OneTime/Dynamic Mixed - compound attribute', function(done) { var div = createTestHtml( '