User tests: Successful: Unsuccessful:
If you want to process raw post data send to an (open) API, you probably would use something similar to this.:
$payload = $this->input->json->getArray();
This is fine when (valid) data was send. In case of an empty request though, a null value is passed to Input::getArrayRecursive()
, which results in the following warning:
Warning: Invalid argument supplied for foreach() in [...]\libraries\src\Input\Input.php on line 165
First, create a test controller "foobar" with the following content in e.g. /components/com_users/controllers/foobar.php
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
JLoader::register('UsersController', JPATH_COMPONENT . '/controller.php');
class UsersControllerFoobar extends UsersController
{
public function foobar()
{
$payload = $this->input->json->getArray();
print_r($payload);
Factory::getApplication()->close();
}
}
Send a POST request, preferably with the content type "application/json" to that controller / method and leave out the payload / data. It shouldn't matter if you use curl, your browser console and / or an addons to do that.
The expected result would be an empty array.
The warning mentioned above appears.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
RTC.
Labels |
Added:
?
|
I would expect that this is a b/c break, because it could changes the behavior on broken json input. I would suggest to make this PR against the 2.0 version of the framework package. Oh I noticed that this is already done.
I'm closing, thanks for your contribution.
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-08-17 10:39:02 |
Closed_By | ⇒ | HLeithner |
This should not have been closed. This fixes PHP notices in core library. The notice can be invoked by user input and can not be fixed by extension developers (except by silencing the error). Plus this has already been fixed in 1.x version of framework package (included in CMS).
Can the developer detect an broken json string if we use this? Shouldn't getArrayRecrusive check if it's an array before it run the foreach loop?
Can the developer detect an broken json string if we use this?
Developer can use getRaw()
method to get the JSON encoded string if needed.
Shouldn't getArrayRecrusive check if it's an array before it run the foreach loop?
Joomla\Input\Input::$data
should always be an array.
You are right data
have to be an array. Thanks
Status | Closed | ⇒ | New |
Closed_Date | 2020-08-17 10:39:02 | ⇒ | |
Closed_By | HLeithner | ⇒ | |
Labels |
Removed:
?
|
Status | New | ⇒ | Pending |
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-08-18 09:10:48 |
Closed_By | ⇒ | HLeithner |
Title |
|
I have tested this item✅ successfully on 4e98f63
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30095.