-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
inverted sections where value is an empty string #186
Comments
I've noticed a discrepancy regarding this issue between this JS implementation and the PHP Mustache version developed here: https://github.com/bobthecow/mustache.php The PHP version treats an empty string as falsy. In the case above it would output: value is empty. |
Per the spec, empty strings should be falsey if the host language treats them as falsey. |
I noticed this also. Empty strings don't seem to work - I had to convert all empty strings to |
Came here to report the similar issue so from this page http://mustache.github.com/mustache.5.html In the Inverted Sections there's a template Putting it into the demo http://mustache.github.com/#demo Doesn't produce the correct outcome and that's using mustache.js, is this the same issue as this or a new one? |
+1 This is pretty critcal. |
+1 |
Just ran into this too. Agree with bobthecow, the spec states that falsey values should be treated as empty lists. This is what pystache does. |
I'd prefer not to make strings falsey in mustache.js to preserve compatibility with people's working code. However, if this is the consensus of the community then we can definitely go in that direction. By that same reasoning |
I am not opposed to this change. 0, NaN, and "" all evaluate to false when coerced (with !!), so they should trigger an inverted section according to the spec:
|
If value is an empty string it is not matched by either a section or an inverted section.
value = ""
{{#value}}
value is {{value}}
{{/value}}
{{^value}}
value is empty
{{/value}}
will output nothing.
The man page says:
A section will be rendered if it "has a non-false value"
An inverted section "will be rendered if the key doesn't exist, is false, or is an empty list."
An empty string equates to false and therefore the expected behaviour would be for an empty string to be matched by an inverted section.
The text was updated successfully, but these errors were encountered: