Skip to content
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

negative instanceof fails #191

Closed
schinkel-zz opened this issue Feb 23, 2016 · 1 comment
Closed

negative instanceof fails #191

schinkel-zz opened this issue Feb 23, 2016 · 1 comment

Comments

@schinkel-zz
Copy link

After #92 another issue seems to have been introduced concerning instanceof parsing.

Consider the following template:

{$interface = 'a_random_interface'}
{$object = 'a string'}
{if $object instanceof $interface
    || $object instanceof a_random_interface}
    <p>$object is an instance of {$interface|escape}</p>
{else}
    <p>$object NOT is an instance of {$interface|escape}</p>
{/if}

{if !$object instanceof $interface
    || !$object instanceof a_random_interface}
    <p>$object NOT is an instance of {$interface|escape}</p>
{else}
    <p>$object is an instance of {$interface|escape}</p>
{/if}

Expected output is:

$object NOT is an instance of a_random_interface
$object NOT is an instance of a_random_interface

This output is produced until Smarty 3.1.21. In following versions an error is given (output is based on Smarty 3.1.29, so after applying the fix for #92):

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:~/templates/correct.tpl" on line 10 "{if !$object instanceof $interface" - Unexpected " instanceof ", expected one of: "}" <-- thrown in ~/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 10

Note that putting parentheses around the instanceof corrects the behaviour:

{if !($object instanceof $interface)
    || !($object instanceof a_random_interface)}
    <p>$object NOT is an instance of {$interface|escape}</p>
{else}
    <p>$object is an instance of {$interface|escape}</p>
{/if}

Following code is used to render the template:

require_once 'vendor/autoload.php';

$smarty = new \Smarty();
$smarty
    ->setCompileDir(sys_get_temp_dir())
    ->setCacheDir(sys_get_temp_dir())
    ->setPluginsDir(SMARTY_PLUGINS_DIR)
    ->disableSecurity();
$smarty->display(__DIR__ . '/templates/correct.tpl');
@uwetews
Copy link
Contributor

uwetews commented Feb 25, 2016

This fix is now in the master branch and will later be included in 3.1.30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants