? 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 matrikular matrikular - change - 13 Jul 2020
Title
Set variable (type) in case of an empty requests
Set variable (type) in case of an empty request
avatar matrikular matrikular - edited - 13 Jul 2020
avatar matrikular matrikular - change - 13 Jul 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-07-13 17:43:40
Closed_By matrikular
Labels Added: ?
avatar matrikular matrikular - close - 13 Jul 2020

Add a Comment

Login with GitHub to post a comment