Просмотр исходного кода

Don't evaluate lambdas that return falsy values as an empty string.

Issue: If I create a Mustache lambda to return numbers and I expect 0 to be of
those numbers, I'll instead only receive an empty string for 0 because it
evaluates to falsy.

Fix: Check the result of the lambda to be undefined or null. Only then should
it return the empty string.
tags/0.7.1
Matt Sacks 13 лет назад
Родитель
Сommit
d59f02f622
4 измененных файлов: 11 добавлений и 1 удалений
  1. +2
    -1
      mustache.js
  2. +7
    -0
      test/_files/check_falsy.js
  3. +1
    -0
      test/_files/check_falsy.mustache
  4. +1
    -0
      test/_files/check_falsy.txt

+ 2
- 1
mustache.js Просмотреть файл

@@ -254,7 +254,8 @@ var Mustache;
return self.render(template, context);
};

return value.call(context.view, text, scopedRender) || "";
var result = value.call(context.view, text, scopedRender);
return result != null ? result : "";
default:
if (value) {
return callback(this, context);


+ 7
- 0
test/_files/check_falsy.js Просмотреть файл

@@ -0,0 +1,7 @@
({
number: function(text, render) {
return function(text, render) {
return +render(text);
}
}
})

+ 1
- 0
test/_files/check_falsy.mustache Просмотреть файл

@@ -0,0 +1 @@
<p>{{#number}}0{{/number}}</p>

+ 1
- 0
test/_files/check_falsy.txt Просмотреть файл

@@ -0,0 +1 @@
<p>0</p>

Загрузка…
Отмена
Сохранить