Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weierophinney opened this issue Dec 31, 2019 · 0 comments

Comments

@weierophinney
Copy link
Contributor

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

Originally posted by @leogr at zfcampus/zf-api-problem#29

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

No branches or pull requests

1 participant