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

You must specify a non-empty path to clean #43580

Closed
bcraigie opened this issue May 30, 2024 · 5 comments
Closed

You must specify a non-empty path to clean #43580

bcraigie opened this issue May 30, 2024 · 5 comments

Comments

@bcraigie
Copy link

Steps to reproduce the issue

Create a menu item that points to something belonging to a component. For example a form in Chronoforms.

Remove that component (perhaps you've installed a newer version of it)

You can see that the menu page shows you "component not found". Try to edit the menu item.

Expected result

Be able to edit the menu item to be able to point it elsewhere (for example a newer version of the component)

Actual result

Stack trace is produced as follows:

Function Location

1 () JROOT/libraries/vendor/joomla/filesystem/src/Path.php:194
2 Joomla\Filesystem\Path::clean() JROOT/administrator/components/com_menus/src/Model/ItemModel.php:1131
3 Joomla\Component\Menus\Administrator\Model\ItemModel->preprocessForm() JROOT/libraries/src/MVC/Model/FormBehaviorTrait.php:115
4 Joomla\CMS\MVC\Model\FormModel->loadForm() JROOT/administrator/components/com_menus/src/Model/ItemModel.php:517
5 Joomla\Component\Menus\Administrator\Model\ItemModel->getForm() JROOT/libraries/src/MVC/View/AbstractView.php:159
6 Joomla\CMS\MVC\View\AbstractView->get() JROOT/administrator/components/com_menus/src/View/Item/HtmlView.php:88
7 Joomla\Component\Menus\Administrator\View\Item\HtmlView->display() JROOT/libraries/src/MVC/Controller/BaseController.php:697
8 Joomla\CMS\MVC\Controller\BaseController->display() JROOT/administrator/components/com_menus/src/Controller/DisplayController.php:74
9 Joomla\Component\Menus\Administrator\Controller\DisplayController->display() JROOT/libraries/src/MVC/Controller/BaseController.php:730
10 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/libraries/src/Dispatcher/ComponentDispatcher.php:143
11 Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:361
12 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/AdministratorApplication.php:150
13 Joomla\CMS\Application\AdministratorApplication->dispatch() JROOT/libraries/src/Application/AdministratorApplication.php:195
14 Joomla\CMS\Application\AdministratorApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:306
15 Joomla\CMS\Application\CMSApplication->execute() JROOT/administrator/includes/app.php:58
16 require_once() JROOT/administrator/index.php:32

System information (as much as possible)

Joomla! Version Joomla! 5.1.0 Stable [ Kudumisha ] 16-April-2024 16:00 GMT

Additional comments

In the file JROOT/libraries/vendor/joomla/filesystem/src/Path.php

In this scenario the $path is a boolean, not a string (because the component doesn't exist)

At this statement:

public static function clean($path, $ds = \DIRECTORY_SEPARATOR)
{
if (!\is_string($path)) {
throw new \InvalidArgumentException('You must specify a non-empty path to clean');
}

Before the if statement, you could check if $path is (presumably) False, and if so, just return. There is no need to crash out. This enables the editing of the menu item to proceed without the user having to resort to editing the Path.php file to fix it, or having to delete their menu item and re-create it. A stack trace is never desirable when a simple fix can be made.

@brianteeman
Copy link
Contributor

A stack trace is never desirable when a simple fix can be made.

You only get the stack trace if you have debug enabled. In normal use you get

image

But if you have a fix that is more helpful please submit a pull request with that code

@bcraigie
Copy link
Author

Hi Brian. Ah yes! I do have debug on and you are correct. It would still be preferable to enable the user to edit the menu item than to receive the error.

I've never submitted a pull request before, and I don't know if the fix I would suggest is acceptable, however it works for me (tested) by simply replacing the "throw new..." line I quoted above with "return;"

The thing I don't know is if there are ever any circumstances where one would desire the error message instead of silently ignoring the problem because I don't have enough in-depth knowledge of the code that may call it under other circumstances. It certainly fixes this specific scenario.

I shall see if I can submit the pull request. :-)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43580.

@chmst chmst added the bug label May 31, 2024
@rdeutz
Copy link
Contributor

rdeutz commented Jun 1, 2024

I think your fix is at the wrong place and would have to many side effects. Then main problem here is that the application can't load the form definition for the menu item. This is something you can't fix in a proper way. I think in such situations deleting the menu item and creating a new one would be the way to go.

@OctavianC
Copy link
Contributor

Please test #43604 as this should solve the issue at the com_menus level instead of globally on the Path class.

@alikon
Copy link
Contributor

alikon commented Jun 3, 2024

closing as we have a pr #43604

@alikon alikon closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants