ソースを参照

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年前
コミット
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>

読み込み中…
キャンセル
保存