nrueckmann / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

Variables in Custom Resource Plugin Names get removed when included inside {block}s #163

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
A template without blocks like

<code>
{$foo="bar"}

{include file="file.{$foo}.html"}
<br/>
{include file="translate:without.block.{$foo}.html"}
<br/>
</code>

will correctly include the two resources "file.bar.html" and 
"translate.without.block.bar.html". 

If we add a {block} around it like 

<code>
{block main}
    {$foo="bar"}

    {include file="file.{$foo}.html"}
    <br/>
    {include file="translate:with.block.{$foo}.html"}
    <br/>
{/block}
</code>

it will correctly include "file.bar.html", but incorrectly include 
"translate.with.block..html". The variable was removed. A notice is reported, 
as well (see attachment notice.html). 

The issue started with Smarty 3.1.15 when the block interpreter was rewritten 
and using variable resource names inside blocks was incorrectly forbidden. 
Since 3.1-DEV (svn-version) the described behavior occurs. 

Smarty versions 3.1.14 and 3.1.13 work as expected. 

Attached is a test script also containing smarty versions 3.1.13 to 3.1-DEV. 
The output of the test script using the different versions can be found below.

notice.html contains the output for 3.1-DEV without supressing errors. 
notice.txt a non-formated textual representation of notice.html. 

System: 
Mac OS X 10.9 (also occured on 10.6 and 10.7)
Apache/2.2.24 
PHP/5.5.5
Smarty 3.1-DEV (SVN revision 4792) 

Output of test script, without notices: 

# Smarty-3.1-DEV
included file file.bar.html
included resource without.block.bar.html
included file file.bar.html
included resource with.block..html 

# Smarty-3.1.15
included file file.bar.html
included resource without.block.bar.html 
# Exception: "variable template file names not allow within {block} tags" (Bug 
already reported and fixed in SVN)

# Smarty-3.1.14
included file file.bar.html
included resource without.block.bar.html
included file file.bar.html
included resource with.block.bar.html 

# Smarty-3.1.13
included file file.bar.html
included resource without.block.bar.html
included file file.bar.html
included resource with.block.bar.html 

Original issue reported on code.google.com by smisch.b...@gmail.com on 28 Oct 2013 at 4:52

Attachments:

GoogleCodeExporter commented 8 years ago
The fix is now in the SVN trunk and will later be included in 3.1.16

Original comment by Uwe.Tews@googlemail.com on 28 Oct 2013 at 6:24

GoogleCodeExporter commented 8 years ago
Hey Uwe,

thanks for the fast fix, works like a charm. 

I'm still getting a notice when calling an already compiled template that used 
a custom resource plugin (see attachment for formatted version)

It turns out that Smarty_Resource::source is called with the argument 
$_template == null. You are checking whether $_template->parent instanceof 
Smarty_Internal_Template on line 533 of sysplugins/smarty_resource.php which 
throws the notice in this case. A simple isset will probably suffice. 

best regards
Sebastian

unformatted notice:
# Smarty-3.1-DEV 
included file file.bar.html 

( ! ) Notice: Trying to get property of non-object in 
/Library/WebServer/Websites/smarty/Smarty-3.1-DEV/libs/sysplugins/smarty_resourc
e.php on line 533
Call Stack
#   Time    Memory  Function    Location
1   0.0005  238072  {main}( )   ../index.php:0
2   0.0123  1168208 Smarty_Internal_TemplateBase->display( string(18), ???, ???, 
??? )   ../index.php:17
3   0.0123  1172464 Smarty_Internal_TemplateBase->fetch( string(18), null, null, 
null, bool, ???, ??? )  ../smarty_internal_templatebase.php:377
4   0.0132  1217008 content_526ed8fb67f223_16471959( 
object(Smarty_Internal_Template)[4] )   ../smarty_internal_templatebase.php:182
5   0.0141  1235208 Smarty_Internal_Template->getSubTemplate( string(32), null, 
null, long, null, array(0), long 
)   ../687c219a729b54a047563c3f7808b66e31f28faf.file.without.block.html.php:31
6   0.0141  1236584 Smarty_Internal_TemplateBase->fetch( null, null, null, null, 
bool, bool, bool )  ../smarty_internal_template.php:284
7   0.0146  1250208 include( 
'/Library/WebServer/Websites/smarty/templates_c/7677d8e629292f158e1c185b22f2bdde
4b589481.translate.without.block.bar.html.php' 
)   ../smarty_internal_templatebase.php:160
8   0.0146  1252280 Smarty_Internal_Template->decodeProperties( array(6), bool 
)   ../7677d8e629292f158e1c185b22f2bdde4b589481.translate.without.block.bar.html.p
hp:21
9   0.0147  1253384 Smarty_Resource::source( null, object(Smarty)[1], string(32) 
)   ../smarty_internal_template.php:460
included resource without.block.bar.html 
included file file.bar.html 

( ! ) Notice: Trying to get property of non-object in 
/Library/WebServer/Websites/smarty/Smarty-3.1-DEV/libs/sysplugins/smarty_resourc
e.php on line 533
Call Stack
#   Time    Memory  Function    Location
1   0.0005  238072  {main}( )   ../index.php:0
2   0.0271  1241056 Smarty_Internal_TemplateBase->display( string(15), ???, ???, 
??? )   ../index.php:18
3   0.0271  1241248 Smarty_Internal_TemplateBase->fetch( string(15), null, null, 
null, bool, ???, ??? )  ../smarty_internal_templatebase.php:377
4   0.0279  1277696 content_526ed8fb6bea06_74925864( 
object(Smarty_Internal_Template)[5] )   ../smarty_internal_templatebase.php:182
5   0.0280  1278752 Smarty_Internal_Template->getSubTemplate( string(29), null, 
null, long, null, array(0), long 
)   ../6972492068f4bd723c47d1fb6f4efbf3cb2c301b.file.with.block.html.php:32
6   0.0280  1280128 Smarty_Internal_TemplateBase->fetch( null, null, null, null, 
bool, bool, bool )  ../smarty_internal_template.php:284
7   0.0285  1292856 include( 
'/Library/WebServer/Websites/smarty/templates_c/c6e66b09e824bd281d4ac78524386dcc
2f016989.translate.with.block.bar.html.php' 
)   ../smarty_internal_templatebase.php:160
8   0.0285  1294904 Smarty_Internal_Template->decodeProperties( array(6), bool 
)   ../c6e66b09e824bd281d4ac78524386dcc2f016989.translate.with.block.bar.html.php:
21
9   0.0286  1296008 Smarty_Resource::source( null, object(Smarty)[1], string(29) 
)   ../smarty_internal_template.php:460
included resource with.block.bar.html 

Original comment by smisch.b...@gmail.com on 28 Oct 2013 at 10:21

Attachments:

GoogleCodeExporter commented 8 years ago
Missed that one.
The fix is now in the SVN

Original comment by Uwe.Tews@googlemail.com on 28 Oct 2013 at 11:57