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

fixed deprecation crash (passing null to json_decode()) #82

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Classes/Service/Tika/ServerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ public function ping()
public function extractMetadataFromLocalFile($fileName)
{
$content = $this->send('PUT', '/meta', 'application/json', $fileName);
$metadata = json_decode($content, true);

return $metadata ?? [];
$metadata = empty($content) ? [] : json_decode($content, true);
return $metadata;
Comment on lines +123 to +124
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we still need the return $metadata ?? [] in case json_decode fails somehow

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the crash occurs in 123... the execution stops before the ternary can be called...

PHP 8.2.15

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't say the rest of the patch didn't look good :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? :D
I meant that the original line 123 crashed, before the ternary can choose something ^^

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that if somehow $content is not empty and CANNOT be properly decoded as JSON, then the second part of the ternary with the json_decode you use will put something that is not an array into $metadata, thus the return statement should (still) take care of that imho.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function json_decode() can't use NULL as first parameter... at least PHP 8.2.15.. so if $content is NULL in 123, the execution stops... no matter what happens afterwards...

}

/**
Expand Down