Skip to content

[BUG] getJsonRawBody() never returns false #13501

Closed
@michalzielanski

Description

The condition in the getJsonRawBody() method looks like this:

let rawBody = this->getRawBody();
if typeof rawBody != "string" {
return false;
}

getRawBody() method looks like this:

let rawBody = this->_rawBody;
if empty rawBody {
let contents = file_get_contents("php://input");
/**
* We need store the read raw body because it can't be read again
*/
let this->_rawBody = contents;
return contents;
}
return rawBody;

file_get_contents("php://input") always return string, so the condition if typeof rawBody != "string" is never satisfied.

I think the getJsonRawBody() method should look like this:

public function getJsonRawBody(boolean associative = false) -> <\stdClass> | array | boolean
{
	var rawBody, data;

	let rawBody = this->getRawBody();
	if rawBody === "" {
		return false;
	}

	let data = json_decode(rawBody, associative);

	if json_last_error() !== JSON_ERROR_NONE {
		return false;
	}

	return data;
}

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions