Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined list passed to {{#each}} #602

Merged
merged 1 commit into from Dec 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions view/mustache/mustache.js
Expand Up @@ -1890,6 +1890,10 @@ function( can ){
* </ul>
*/
'each': function(expr, options) {
if(!expr) {
return;
}

if(expr.isComputed || isObserveLike(expr) && typeof expr.attr('length') !== 'undefined'){
return can.view.lists && can.view.lists(expr, function(item, key) {
// Create a compute that listens to whenever the index of the item in our list changes.
Expand Down
9 changes: 9 additions & 0 deletions view/mustache/mustache_test.js
Expand Up @@ -2585,4 +2585,13 @@ test('html comments must not break mustache scanner', function(){
});
})

test("{{each}} does not error with undefined list (#602)", function() {
var renderer = can.view.mustache('<div>{{#each data}}{{name}}{{/each}}</div>');

equal(renderer.render({}), '<div></div>', 'Empty text rendered');
equal(renderer.render({ data: false }), '<div></div>', 'Empty text rendered');
equal(renderer.render({ data: null }), '<div></div>', 'Empty text rendered');
equal(renderer.render({ data: [ { name: 'David' }] }), '<div>David</div>', 'Expected name rendered');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should test updating a can.Map's list property to null then to an array and then back to null.

});

})();