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
Fix folderlist on Windows-based web servers #12841
Conversation
On non-windows-based web servers, the current code works fine, but on windows-based web servers, like IIS or WAMP, the folderlist options will look like "C:\wamp\www\/images" or "C:\inetpub\wwwroot\/images", when it should only show as "images". This messes up any extension that uses folderlist on windows-based web servers. I propose to change line 219 from: $folder = trim(str_replace($path, '', $folder), '/'); to: $folder = trim(str_replace(rtrim($path, '/\\'), '', $folder), '/\\'); This essentially accommodates Windows systems to make the folderlist work as it should.
This issue still exists in Joomla 3.6.4. My solution is different from those proposed. One of the problems with the current code is that the $path variable string actually has a trailing slash, which is why the folder root path is not removed by the str_replace on line 219. It should be trimmed. |
I have tested this item 🔴 unsuccessfully on 972fa74 If the original folder has "/" then JFolder will "clean" it thus replace the "/" with "" (windows seperator) This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12841. |
@ggppdk I don't quite understand your comment. When you say "original folder" are you referring to the value of $path or $folder (just before line 219)? Because $path is the root path of the folder list, and $folder is the full path of a subfolder in the folder list, the purpose of line 219 is to remove the root path from the full path, and leave only the subfolder, without any slashes before or after it. Could you better clarify the use case in which:
would fail to provide the subfolder name? Thanks. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12841. |
JFolder::folders($path, ... Returns:
Now this e.g. thus you PR will fail with
but you PR will fail even fail with:
because folderlist does: if (!is_dir($path))
{
$path = JPATH_ROOT . '/' . $path;
} In any case please test this PR: #11288 |
I needed to clean the $path contents since it will be used later when trying to remove it from the subfolder's full path. It is cleaned inside of JFolder::folders, but only in the scope of that function. It needs to be cleaned before it is used by JFolder::folder
Thanks for the clarification. You are right. I think the best thing to do is to clean the $path variable before using it to find the subfolders with JFolder. See my update: f73febd This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12841. |
Closing this in favour of #14139 as we had 4 different PR's for the same issue :) |
Pull Request for Issue # .
Summary of Changes
On line 219, the root folder path is trimmed on the end of both back and forward slashes, and the resulting folder is trimmed of both back and forward slashes.
Testing Instructions
The changes address the issue of folderlist on Windows-based web servers. You can test this on IIS or WAMP, just access any module (or plugin) that uses folderlist, and you will see "C:\wamp\www/images" or "C:\inetpub\wwwroot/images", when it should only show as "images".
Since there are no built-in extensions that use folder list, you can add the following field to any module's xml file to test it:
<field name="test_field" type="folderlist" default="images" label="TEST_LABEL" directory="" description="TEST_DESC" hide_none="true" hide_default="true" exclude="^[Aa]dministrator$|^[Cc]ache$|^[Cc]omponents$|^[Cc]li$|^[Ii]ncludes$|^[Ll]anguage$|^[Ll]ibraries$|^[Ll]ogs$|^[Mm]odules$|^[Pp]lugins$|^[Tt]emplates$|^[Xx]mlrpc$" />
Documentation Changes Required
On non-windows-based web servers, the current code works fine, but on windows-based web servers, like IIS or WAMP, the folderlist options will look like "C:\wamp\www/images" or "C:\inetpub\wwwroot/images", when it should only show as "images". This messes up any extension that uses folderlist on windows-based web servers.
I propose to change line 219 from:
$folder = trim(str_replace($path, '', $folder), '/');
to:
$folder = trim(str_replace(rtrim($path, '/\\'), '', $folder), '/\\');
This essentially accommodates Windows systems to make the folderlist work as it should.