smarty icon indicating copy to clipboard operation
smarty copied to clipboard

Smarty fails with any plugin that ends in 'close'

Open calguy1000 opened this issue 11 years ago • 5 comments

Sample code:

registerPlugin('function','testclose','test_plugin',false); $tpl = '{testclose}'; $smarty->display('string:'.$tpl); ?>

Error:

PHP Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "4f51b386251639c28dd52ffe53b55c127b1faa69" on line 1 "{testclose}" unknown tag "testclose" <-- thrown in /nfs/u1404/smarty_test/smarty-3.1.24/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 1

Note:

Changing the plugin name to 'testfoo' and the call in the template to {testfoo} provides the expected output.

calguy1000 avatar Jun 10 '15 00:06 calguy1000

looks like https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatecompilerbase.php#L521 is the problem

echo substr($tag, - 5); above this line says 'close' if you look at line https://github.com/smarty-php/smarty/blob/master/libs/sysplugins/smarty_internal_templatecompilerbase.php#L638 you see that the 'close' will be removed and then it will trigger the error becouse your plugin has the name 'testclose' and not 'test'

i think @uwetews need to check this

Stricted avatar Jun 10 '15 01:06 Stricted

Smarty does use tag names ending with close internally to handle closing tags. Like {/foo} => fooclose. You should not use it as a standalone plugin name.

It allows for example to write compiler plugins for block tags usage. One compiler plugin 'foo' and one for 'fooclose' to use {foo} .... {/foo}.

uwetews avatar Jun 11 '15 19:06 uwetews

Well, the problem is that older versions of smarty (2.x) didn't do that... and there are valid cases where people have written smarty plugins for various third party packages using smarty with the name 'close' in them, and those plugins are years old...... maybe they could have used a block tag, but they didn't. i.e: tags like {form_open} or {form_close} or {togglearea_open} and {togglearea_close}

And now those plugins cause an error in smarty 3.

Is it possible to change smarty in the next version to use a delimiter like: "_smartyclose" or something that is less likely to conflict with valid tag names.

On Thu, Jun 11, 2015 at 1:06 PM, uwetews [email protected] wrote:

Smarty does use tag names ending with close internally to handle closing tags. Like {/foo} => fooclose. You should not use it as a standalone plugin name.

It allows for example to write compiler plugins for block tags usage. One compiler plugin 'foo' and one for 'fooclose' to use {foo} .... {/foo}.

— Reply to this email directly or view it on GitHub https://github.com/smarty-php/smarty/issues/52#issuecomment-111242562.

calguy1000 avatar Jun 11 '15 19:06 calguy1000

If I do that Smarty 3 users which have written compiler plugins for closing tags will get errors. What I can do is to handle tags ending with "_close" like normal plugins tag.

uwetews avatar Jun 11 '15 22:06 uwetews

This problem is now resolved. Function plugins can now have names ending with 'close'. The fix is in dev-master and will later be included in the 3.1.28 release.

uwetews avatar Jun 27 '15 20:06 uwetews