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

{include} function breaks output when enable cache #300

Closed
fumiya-takeishi opened this issue Sep 28, 2016 · 4 comments
Closed

{include} function breaks output when enable cache #300

fumiya-takeishi opened this issue Sep 28, 2016 · 4 comments

Comments

@fumiya-takeishi
Copy link

Hello,

I have a problem with {include} function when enable cache. A problem has occurred since Smarty-3.1.29+.
Here is minimal reproduce code:

reproduce.php :

<?php

require_once 'Smarty.class.php';

$smarty = new Smarty();
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCacheLifetime(10);

$smarty->display("./xml_output.tpl", "test_xml");

xml_output.tpl :

{include file="./xml_head.tpl"}

xml_head.tpl :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

I expect output of reproduce.php :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

But since Smarty-3.1.29+ :

/*%%SmartyNocache:12514421357eb3f04a1b651_10795127%%*/<?php echo '<?xml ';?>
/*/%%SmartyNocache:12514421357eb3f04a1b651_10795127%%*/version="1.0" encoding="UTF-8" standalone="yes"/*%%SmartyNocache:12514421357eb3f04a1b651_10795127%%*/<?php echo '?>';?>
/*/%%SmartyNocache:12514421357eb3f04a1b651_10795127%%*/

If reproduce.php changes

$smarty->display("./xml_output.tpl", "test_xml");

to

$smarty->display("./xml_head.tpl", "test_xml");

or disable smarty cache, it works correctly.
But i must use {include} function with smarty cache for my projects.

Thanks.

@uwetews
Copy link
Contributor

uwetews commented Sep 28, 2016

This bug is fixed now in the master branch

@uwetews uwetews closed this as completed Sep 28, 2016
@fumiya-takeishi
Copy link
Author

Thanks for fix this issue.

In my project, we found another cases which break output. An issue occurs in Smarty-dev/34 + PHP7.
Here is minimal reproduce code:

Program

reproduce.php :

<?php

require_once 'Smarty.class.php';

$smarty = new Smarty();
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCacheLifetime(10);

$smarty->display("./output.tpl", "test");

output.tpl :

{include file="./sample_script.tpl"}
{include file="./sample_html_no_quotes_attr.tpl"}

sample_script.tpl (case 1 : '<? ') :

<script type="text/javascript">
console.log("some_val".match(/<? div/));
</script>

sample_html_no_quotes_attr.tpl (case 2 : '%>') :

<div width=100%>test</div>

Result

expect:

<script type="text/javascript">
console.log("some_val".match(/<? div/));
</script>
<div width=100%>test</div>

actual:

<script type="text/javascript">
console.log("some_val".match(//*%%SmartyNocache:152730339357fdcf3eb338a3_04160183%%*/<?php echo '<? ';?>/*/%%SmartyNocache:152730339357fdcf3eb338a3_04160183%%*/div/));
</script>
<div width=100/*%%SmartyNocache:171072921957fdcf3eb3a320_05965105%%*/<?php echo '%>';?>/*/%%SmartyNocache:171072921957fdcf3eb3a320_05965105%%*/test</div>

Same as last, if we don't use {include} function or disable smarty cache, it works correctly.

Thanks.

uwetews added a commit that referenced this issue Oct 19, 2016
…did contain PHP short tags in text but no other

    nocache code #300
@uwetews
Copy link
Contributor

uwetews commented Oct 19, 2016

This bug is now fixed in the master branch

@fumiya-takeishi
Copy link
Author

Thanks for fixing issues!

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