Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

fetch bug

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
gyopee
Smarty Rookie


Joined: 27 Jan 2014
Posts: 14

PostPosted: Thu Jan 30, 2014 8:29 am    Post subject: fetch bug Reply with quote

In case I'd like to fetch a php file, Smarty {fetch} function returns a weird result.

For example:

PHP to fetch:
Code:
<?php
   require_once 'libs/Smarty.class.php';
   $smarty = new Smarty();
   $smarty->display('smarty.htm');


Expected result:
Code:
<?php
   require_once 'libs/Smarty.class.php';
   $smarty = new Smarty();
   $smarty->display('smarty.htm');


Displayed:
Code:
display('smarty_counter_and_cycle.htm');


That's basically not a Smarty bug.
It's because file_get_contents PHP function.
But Smarty can avoid using file_get_contents, for example in this way:

In function.fetch.php the block starting at line 208 should be changed from:
Code:

    $content = @file_get_contents($params['file']);
    if ($content === false) {
        throw new SmartyException("{fetch} cannot read resource '" . $params['file'] ."'");
    }

to:
Code:

   $fp = @fopen($params['file'],'r');
   if($fp===false){
      throw new SmartyException("{fetch} cannot read resource '" . $params['file'] ."'");
   }
   else{
      $content = htmlspecialchars(fread($fp,filesize($params['file'])));
      fclose($fp);
   }
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Jan 30, 2014 5:37 pm    Post subject: Reply with quote

This is not a bug. It is intended that fetch does display the fetch content as it is.

For example {fetch} can be used to load dynamically JavaScript files from remote servers or the local file system.

If you would run the content through htmlspecialchars you would get the js files displayed which is not intended.

If you want to display as in your example the content of a PHP source file you can do it by adding modifier

Code:
{fetch|htmlspecialchars|nl2br file='./foo.php'}
Back to top
View user's profile Send private message
gyopee
Smarty Rookie


Joined: 27 Jan 2014
Posts: 14

PostPosted: Thu Jan 30, 2014 7:03 pm    Post subject: Reply with quote

Yes, you are right.

My bad.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP