? Success

User tests: Successful: Unsuccessful:

avatar AbhishekDas
AbhishekDas
4 Feb 2015

JPATH_BASE . '/' does not always remove the base path as DIRECTORY_SEPARATOR varies with platform. This should be replaced with JPATH_BASE . DIRECTORY_SEPARATOR.

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
3.00

avatar AbhishekDas AbhishekDas - open - 4 Feb 2015
avatar jissues-bot jissues-bot - change - 4 Feb 2015
Labels Added: ?
avatar richard67
richard67 - comment - 4 Feb 2015

A snake oil PR, i.e. has no effect, because 1 line later any "\" is replaced by "/" in $path using str_replace, and so at the end all is "/", or not?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5967.
avatar AbhishekDas
AbhishekDas - comment - 4 Feb 2015

Probably you did not understand the issue. Ok, let me explain then.

Consider the following :

JPATH_BASE = 'D:\xampp\htdocs\joomla';
$dir = 'D:\xampp\htdocs\joomla\templates\protostar\favicon.ico';

$path = str_replace(JPATH_BASE . '/', '', $dir);

will not replace anything. Result:

$path = 'D:\xampp\htdocs\joomla\templates\protostar\favicon.ico';

$path = str_replace('\\', '/', $path);

Result:

$path = 'D:/xampp/htdocs/joomla/templates/protostar/favicon.ico';

$this->addFavicon(JUri::base(true) . '/' . $path . 'favicon.ico');

End result:

<link href="joomla/D:/xampp/htdocs/joomla/templates/protostar/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />

Now does it sound logical? If not then you can always test it yourself with xampp under Windows 8.1.

avatar richard67
richard67 - comment - 4 Feb 2015

Yes, you are right, I was wrong with syntax of str_replace of PHP. Sorry for that. But your explanation is also wrong: The "favicon.ico" at the end of $dir would cause a "favicon.icofavicon.ico" at the end of the href, or not?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5967.
avatar AbhishekDas
AbhishekDas - comment - 4 Feb 2015

My bad. I considered a wrong $dir value. Correcting it below:

JPATH_BASE = 'D:\xampp\htdocs\joomla';
$dir = 'D:\xampp\htdocs\joomla\templates\protostar\';

$path = str_replace(JPATH_BASE . '/', '', $dir);

will not replace anything. Result:

$path = 'D:\xampp\htdocs\joomla\templates\protostar\';

$path = str_replace('\\', '/', $path);

Result:

$path = 'D:/xampp/htdocs/joomla/templates/protostar/';

$this->addFavicon(JUri::base(true) . '/' . $path . 'favicon.ico');

End result:

<link href="joomla/D:/xampp/htdocs/joomla/templates/protostar/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />

avatar zero-24 zero-24 - change - 4 Feb 2015
Category Libraries
avatar richard67
richard67 - comment - 4 Feb 2015

@test Tested with success, see following screenshots.

  1. Before patch:
    screen shot 2015-02-04 at 15 23 37

  2. After patch:
    screen shot 2015-02-04 at 15 23 41

Tested on a windows host with latest staging + this PR patched into it.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5967.
avatar richard67 richard67 - test_item - 4 Feb 2015 - Tested successfully
avatar richard67
richard67 - comment - 4 Feb 2015

P.S.: I had in mind there was some discussion and a PR for the same issue before, and now I have found it, it was #5566 by @smz . I left a comment there that now this PR here has been made.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5967.
avatar sovainfo
sovainfo - comment - 4 Feb 2015

Object to introducing DIRECTORY_SEPARATOR into Joomla. Just because some people still don't understand writing platform agnostic code! This should be treated as REGRESSION. The PR introducing the \ as directory separator should be reverted. It is the wrong solution for the issue, even mentioned there!
Joomla should standardize on '/' within its code. Platform differences should be translated to the Joomla standard. The usage of DIRECTORY_SEPARATOR should be limited to those occassions where it is absolutely needed.Don't force all extensions to use DIRECTORY_SEPARATOR ! That is considered a break of BC!

avatar roland-d
roland-d - comment - 14 Apr 2016

@AbhishekDas The introduction of the DIRECTORY_SEPARATOR will not be merged as we actually removed all references to this years ago. Can you update your PR to not use it?

avatar mbabker
mbabker - comment - 14 Apr 2016

He can't. He can either use $path = JPath::clean($dir, '/'); to standardize the entire path to / separators before doing any other operation in that segment or leave it as is because this is a case where you are doing explicit string comparisons on file paths and a valid case where the use of DIRECTORY_SEPARATOR should be considered.

avatar mbabker
mbabker - comment - 14 Apr 2016

BUT, doing the former means that JPATH_BASE would also have to be converted to a standardized separator before that is str_replace()'d out of the path.

avatar richard67
richard67 - comment - 14 Apr 2016

Unfortunately I do not have any testing environment on Windows anymore, and I currently do not plan to set up some again, so I could not help with testing / re-testing. I'll unsubscribe for this reason from this conversation. Wish you all good luck with solving that.

avatar AbhishekDas
AbhishekDas - comment - 14 Apr 2016

I think this PR is no longer required after the recent changes.

This is the existing codes in 3.5.1 -

        foreach (array($directory, JPATH_BASE) as $dir)
        {
            if (file_exists($dir . $icon))
            {
                $path = str_replace(JPATH_BASE, '', $dir);
                $path = str_replace('\\', '/', $path);
                $this->addFavicon(JUri::base(true) . $path . $icon);
                break;
            }
        }

Therefore closing it.

avatar AbhishekDas AbhishekDas - change - 14 Apr 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-04-14 17:36:50
Closed_By AbhishekDas
avatar AbhishekDas AbhishekDas - close - 14 Apr 2016

Add a Comment

Login with GitHub to post a comment