fix #305: do render the value "0" inside conditional#306
fix #305: do render the value "0" inside conditional#306Krinkle wants to merge 2 commits intozordius:masterfrom
Conversation
| $count = count($cx['scopes']); | ||
| $plen = count($path); | ||
| while ($base) { | ||
| while ($base !== null) { |
There was a problem hiding this comment.
When the conditional block processes the path foo from the parent context with array( 'foo' => '0' ) the logic for deciding whether the value is "real" is on line 182, where it only has to pass isset().
The isset() function basically performs to checks: The variable/property/key exists, and has a non-null value.
This successfully unwraps the value '0' from array( 'foo' => '0' ).
The string '0' is then passed into the conditional closure, and Runtime::v() is called again when evaluating the placeholder {{foo}}. This time it is no longer a sub property, and it now implicitly checked by this while statement, which rejects all falsey values in PHP. Including many that isset() accepts. Such as: boolean false, number 0 and string '0'.
4bceeee to
9e8ab9d
Compare
|
Build failure is unrelated, see #307. |
|
Hello, This pull request breaks a handlebars.js spec test, which was definded in handlebars-lang/handlebars.js#731 . Refer to these jsfiddle: handlebars.js 4.1.1: https://jsfiddle.net/0rec6d2f/ Here are some mustache <=> handlebars difference, you can refer to these document: About block: About #if: If you like to follow mustache, the If you like to follow handlebars.js, you should use |
|
@zordius This is about the string The The problem is in the internal lightncandy logic for getting a value from a path, in The example template: {{#foo}}<b>{{foo}}</b>{{/foo}}The example data: 'data' => [
'foo' => '0',
],When
Then, for
The value is never found, and never printed. We get I might need help for a better fix. Do you have a recommendation? |
|
Well, please refer to #305 , we compared handlebars.js and mustache.js there, again. Now the handlebars.js behavior is strange but lightncandy is aligned with it. Here are some points:
|
Fixes issue #305.