Skip to content

Commit b257bc6

Browse files
committed
Treat an empty string (or for that matter, any value that evaluates to false) as falsey in inverted sections.
Fixes issue janl#186 (janl#186)
1 parent 2f135e2 commit b257bc6

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

mustache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
175175
// From the spec: inverted sections may render text once based on the
176176
// inverse value of the key. That is, they will be rendered if the key
177177
// doesn't exist, is false, or is an empty list.
178-
if (value == null || value === false || (isArray(value) && value.length === 0)) {
178+
if (!value || (isArray(value) && value.length === 0)) {
179179
buffer += callback();
180180
}
181181
} else if (isArray(value)) {

spec/_files/inverted_section.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
var inverted_section = {
2-
"repos": []
2+
"repos": [],
3+
"empty_string": ""
34
};

spec/_files/inverted_section.mustache

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{{#repos}}<b>{{name}}</b>{{/repos}}
22
{{^repos}}No repos :({{/repos}}
33
{{^nothin}}Hello!{{/nothin}}
4+
{{^empty_string}}Empty string should be falsey{{/empty_string}}

spec/_files/inverted_section.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
No repos :(
33
Hello!
4+
Empty string should be falsey

0 commit comments

Comments
 (0)