No Code Attached Yet bug
avatar kernusr
kernusr
5 Oct 2021

Problem identified

I hzve plugin with name PlgQuickiconResetMediaVersion and method onAjaxResetMediaVersion
Please note that all names are in camel case
In joomla 3.x this works fine

But in Joomla 4.x is not work

Why?

This happens because the component com_ajax gets the plugin name from the browser address bar "as is" and just capitalizes the first letter

$plugin = ucfirst($input->get('plugin'));
try
{
$results = Factory::getApplication()->triggerEvent('onAjax' . $plugin);
}
catch (Exception $e)
{
$results = $e;
}

If i call index.php?option=com_ajax&plugin=resetmediaversion&group=quickicon&format=json then the component will receive onAjaxResetmediaversion

If i call index.php?option=com_ajax&plugin=ResetMediaVersion&group=quickicon&format=json then the component will receive onAjaxResetMediaVersion

If i call index.php?option=com_ajax&plugin=resetMediaVersion&group=quickicon&format=json then the component will receive onAjaxResetMediaVersion

If i call index.php?option=com_ajax&plugin=resetmediaVERSION&group=quickicon&format=json then the component will receive onAjaxResetmediaVERSION

Of the 4 listed options, only the 2nd and 3rd will be processed correctly. They convert method name to onAjaxResetMediaVersion

This happens because the dispatcher registers methods through reflection.

$reflectedObject = new \ReflectionObject($this);
$methods = $reflectedObject->getMethods(\ReflectionMethod::IS_PUBLIC);

That is, we make the relationship between the method name and the event name case-sensitive.

Perhaps it's good when all calls are made through code. But when a call is made, with parameters obtained from the browser string, this creates some inconvenience.

Open questions

Maybe it is worth registering methods in lower case in dispatcher? This should not lead to ambiguity because php itself regulates this. I cannot declare in the same class myFunction and myfunction.

But that will allow you to avoid ambiguity when calling events. I can call onAjaxMyAwesomeMethodOfClass and onAjaxmyawesomemethodofclass This will make my plugin code look conveniently readable

How sane is this?

avatar kernusr kernusr - open - 5 Oct 2021
avatar joomla-cms-bot joomla-cms-bot - change - 5 Oct 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Oct 2021
avatar PhilETaylor
PhilETaylor - comment - 5 Oct 2021

I would actually say there is a @joomla/security issue here (a slight one) as Joomla is passing the raw value (able it ucfirst) of the plugin var from the url directly to calling a method of that name...

avatar ditsuke
ditsuke - comment - 6 Oct 2021

Thanks for opening this issue. This behavior was bothering me too, not a fan of having to do impure CamelCase.
I needed sleep when I wrote this. In any case I think the suggestion is worth considering.

avatar Fedik
Fedik - comment - 6 Oct 2021

the plugin var from the url directly to calling a method of that name

nope, look closer ;)

avatar Hackwar Hackwar - change - 22 Feb 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 22 Feb 2023

Add a Comment

Login with GitHub to post a comment