Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

fix one time mustache parsing #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,22 @@ suite('Template Instantiation', function() {
});
});

test('OneTime - list/map', function(done) {
var div = createTestHtml(
'<template bind>' +
'<div foo="[[foo[\'bar\']]]:[[zap[0]]]"></div>' +
'</template>');
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(
'<template bind>' +
Expand Down