Skip to content

Commit

Permalink
Treat an empty string (or for that matter, any value that evaluates t…
Browse files Browse the repository at this point in the history
…o false) as falsey in inverted sections.

Fixes issue janl#186 (janl#186)
  • Loading branch information
bgreenlee committed May 1, 2012
1 parent 2f135e2 commit b257bc6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// From the spec: inverted sections may render text once based on the
// inverse value of the key. That is, they will be rendered if the key
// doesn't exist, is false, or is an empty list.
if (value == null || value === false || (isArray(value) && value.length === 0)) {
if (!value || (isArray(value) && value.length === 0)) {
buffer += callback();
}
} else if (isArray(value)) {
Expand Down
3 changes: 2 additions & 1 deletion spec/_files/inverted_section.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var inverted_section = {
"repos": []
"repos": [],
"empty_string": ""
};
1 change: 1 addition & 0 deletions spec/_files/inverted_section.mustache
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{#repos}}<b>{{name}}</b>{{/repos}}
{{^repos}}No repos :({{/repos}}
{{^nothin}}Hello!{{/nothin}}
{{^empty_string}}Empty string should be falsey{{/empty_string}}
1 change: 1 addition & 0 deletions spec/_files/inverted_section.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

No repos :(
Hello!
Empty string should be falsey

0 comments on commit b257bc6

Please sign in to comment.