View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 05, 2017 2:08 pm Post subject: Failing to understand Smarty::_realpath() |
|
|
Can somebody please explain to me, what it does?
The code is so disconnected that I'm failing to make any sense of it. Consequently, unable to debug it, as it is failing in very simple cases of passing it a plain path with no tricks. |
|
Back to top |
|
carpii Smarty Rookie
Joined: 06 Sep 2008 Posts: 18
|
Posted: Sat Dec 30, 2017 12:02 am Post subject: |
|
|
I don't know. It looks like very strange code personally.
My guess is it is used by Smarty to grab an absolute path to a script or base template, when there are subtemplates included.
Try adding some debug output to it, showing the inputs and then the returned path. It might help you to understand why and when its being used |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Dec 30, 2017 1:11 am Post subject: |
|
|
I know, why and when it is used, I don't understand, what it is supposed to do, as it seems to be working purely by accident. |
|
Back to top |
|
carpii Smarty Rookie
Joined: 06 Sep 2008 Posts: 18
|
Posted: Tue Jan 02, 2018 2:37 am Post subject: |
|
|
The more I look at it the less I understand it
From what I can see though, realpath is never called with false (only true or null).
There are some tests in libs/sysplugins/smarty_internal_testinstall.php which might shed some light on it too.
Code like this makes me think it should just be rewritten from scratch (even if it works, it's probably not optimal performance-wise)..
Quote: |
$counts[] = (int)((strlen($m) - 1) / 3);
|
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jan 03, 2018 12:17 am Post subject: |
|
|
carpii wrote: | Code like this makes me think it should just be rewritten from scratch |
That's my full intention. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jan 04, 2018 7:08 pm Post subject: |
|
|
What part of the header description is confusing?
Code: | * Normalize path
* - remove /./ and /../
* - make it absolute if required
*
* @param string $path file path
* @param bool $realpath if true - convert to absolute
* false - convert to relative
* null - keep as it is but remove /./ /../
|
So it removes "." and ".." from the path, and if 2nd param is true, return absolute (system) path, otherwise return relative path. It is compatible with different directory separator types.
If you are testing it directly, make sure DIRECTORY_SEPARATOR is defined the way you want it. ie. use an instance of smarty. It is also going to use your cwd as the relative path location. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jan 07, 2018 12:17 am Post subject: |
|
|
The problem is, the function code is a long mile away from the function description.
I'm going to take another look at it, and rewrite if I don't understand it again. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Jan 09, 2018 1:01 am Post subject: |
|
|
It could probably be rewritten, at the risk of breaking something you don't realize you are breaking. I think this was written quite some time ago, when PHP and the OS's it ran on were quite a different animal. Think directory separators. If you do rewrite it, it could use ample unit testing both positive and negative. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jan 09, 2018 11:00 pm Post subject: |
|
|
That's why I'm asking. I want to be 100% sure I fully understand the intention of this function before fixing it. |
|
Back to top |
|
|