Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

ApiProblemResponse/RenderErrorListener issue while encoding binary data to Json #29

Open
leogr opened this issue Dec 5, 2014 · 1 comment

Comments

@leogr
Copy link

leogr commented Dec 5, 2014

Assume displayExceptions is true.

If in the exception stack trace a function argument contains binary data that json_encode could not handle, then json_encode will return false. As a result the response content is empty.

This happens at following lines:
RenderErrorListener.php#L94
ApiProblemResponse.php#L59

This situation can occur in various debugging scenarios, e.g. uploading a file and passing its blob to a function, and it can be pretty difficult to overcome because the empty response.

Proposed solution
A better choice would be to use \Zend\Json\Encoder::encode because it can correctly handle the encoding of binary data that json_encode can not encode.

// Assuming $data['blob'] contains the binary data of a PDF file

json_encode($data); // return false

\Zend\Json\Json::encode($data); // return false if the json extension is available, otherwise \Zend\Json\Encoder::encode is used

\Zend\Json\Encoder::encode($data); // return the encoded json
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-api-problem; a new issue has been opened at laminas-api-tools/api-tools-api-problem#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants