-
Notifications
You must be signed in to change notification settings - Fork 76
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
fix #305: do render the value "0" inside conditional #306
base: master
Are you sure you want to change the base?
Conversation
@@ -151,7 +151,7 @@ public static function lo($cx, $v) { | |||
public static function v($cx, $in, $base, $path, $args = null) { | |||
$count = count($cx['scopes']); | |||
$plen = count($path); | |||
while ($base) { | |||
while ($base !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.