? Pending

User tests: Successful: Unsuccessful:

avatar matrikular
matrikular
13 Jul 2020

Summary of Changes

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

Testing Instructions

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.

Expected result

The expected result would be an empty array.

Actual result

The warning mentioned above appears.

avatar matrikular matrikular - open - 13 Jul 2020
avatar matrikular matrikular - change - 13 Jul 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 13 Jul 2020
Category Libraries
avatar bonzani bonzani - test_item - 13 Jul 2020 - Tested successfully
avatar bonzani
bonzani - comment - 13 Jul 2020

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.

avatar SharkyKZ SharkyKZ - test_item - 24 Jul 2020 - Tested successfully
avatar SharkyKZ
SharkyKZ - comment - 24 Jul 2020

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.

avatar SharkyKZ SharkyKZ - change - 24 Jul 2020
Status Pending Ready to Commit
Labels Added: ?
avatar SharkyKZ
SharkyKZ - comment - 24 Jul 2020

RTC.


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

avatar matrikular matrikular - change - 24 Jul 2020
Labels Added: ?
avatar HLeithner
HLeithner - comment - 17 Aug 2020

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.

avatar HLeithner HLeithner - change - 17 Aug 2020
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2020-08-17 10:39:02
Closed_By HLeithner
avatar HLeithner HLeithner - close - 17 Aug 2020
avatar SharkyKZ
SharkyKZ - comment - 17 Aug 2020

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).

avatar HLeithner
HLeithner - comment - 17 Aug 2020

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?

avatar SharkyKZ
SharkyKZ - comment - 17 Aug 2020

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.

avatar HLeithner
HLeithner - comment - 18 Aug 2020

You are right data have to be an array. Thanks

avatar HLeithner HLeithner - change - 18 Aug 2020
Status Closed New
Closed_Date 2020-08-17 10:39:02
Closed_By HLeithner
Labels Removed: ?
avatar HLeithner HLeithner - change - 18 Aug 2020
Status New Pending
avatar HLeithner HLeithner - reopen - 18 Aug 2020
avatar HLeithner HLeithner - change - 18 Aug 2020
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-08-18 09:10:48
Closed_By HLeithner
avatar HLeithner HLeithner - close - 18 Aug 2020
avatar HLeithner HLeithner - merge - 18 Aug 2020
avatar HLeithner HLeithner - change - 18 Aug 2020
Title
Set variable (type) in case of an empty request
Set variable (type) in case of an empty request in json input object
avatar HLeithner HLeithner - edited - 18 Aug 2020

Add a Comment

Login with GitHub to post a comment