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
Encoding malformed characters #80
Conversation
Can you refactor this using a single constant Example: |
also, you should never create PR from default branch (always create feature branch), making changes for the PR would mess up your default branch and vice versa. you might want to keep them separate. |
also, while at it, fix Mlaformed -> malformed typo in commit message. |
src/Saver/FileSaver.php
Outdated
|
||
return file_put_contents($this->file, $json . PHP_EOL, FILE_APPEND); | ||
return $result === false ? '' : $result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why put empty line to file? maybe skip whole write then?
src/Saver/FileSaver.php
Outdated
*/ | ||
private function encodeData(array $data) | ||
{ | ||
$result = PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check fails with php 8.0, use PHP_VERSION_ID instead
Please, note that I created a new branch as noted on which the proposed changes are made, including fixed typo in commit message. If you are okay, with that, I will create a new request from that branch. Meanwhile, marking this PR as draft, avoiding the merging |
if you're able to force push those changes to your i prefer if we can continue in this pr, so discussions don't get spread out between multiple pr's. |
|
thank you 🙂 |
No collected data available
While profiling an application, malformed data were sent to a saver (both, Upload and File) that called
json_encode
with the provided data.That resulted into an encoding error, returning false that was casted into an empty string.
Because of that, no collected data was available at the end of the request.
The proposed change uses JSON_INVALID_UTF8_IGNORE constant which removes all invalid characters, making the encoding possible.
The constant is available since PHP 7.2, that is why a 'check' is made before the encoding. If the PHP has the constant, it will use it.
Even though the change removes a word/key from the resulted output, the change does not have any undesirable changes because the previous (current) behavior does not generate the output at all.