pyrocms/pyrocms — Issue #777: Serious bug in conditional tags
Author: sazan
Created: 2011-10-10 06:06:26+00:00
State: open

Hello guys! Just discovered a bug that urgently requires your attention and a fix. Dunno if this is a known one but I didn't find anything about it, so here it is:

Behavior:
When using cascading IF, ELSEIF and ELSE conditional tags within templates or pages, ALL codes within ALL these tags are being evaluated and run. This can be the real problem for those who are using caching and for all others as well too because it gonna make your modules and code run slower by loading the server up with an unexpected code execution.

Proof:
Create simple plugin, i.e. Test:

db->query('SELECT "GOOD" AS good');
echo 'Good is here!';
return $sql->row()->good;
}

function bug ()
{
$sql = $this->db->query('SELECT "Hello Buggy!" AS bug');
echo 'Bug is here!';
return $sql->row()->bug;
}
}
?>

Put this into your template or page:

{if '{pyro:user:logged_in}'}
{pyro:test:good}
{else}
{pyro:test:bug}
{/if}

Access that page with debug enabled

?_debug=1

and see how the code and both queries are being evaluated at once when only 1 should be run. This won't happen when using good ol' php statements like