Skip to content

PHP8 catch ValueError for loadHTML()#673

Merged
mblaney merged 1 commit intosimplepie:masterfrom
FreshRSS:PHP8-catch-ValueError
Mar 23, 2021
Merged

PHP8 catch ValueError for loadHTML()#673
mblaney merged 1 commit intosimplepie:masterfrom
FreshRSS:PHP8-catch-ValueError

Conversation

@Alkarex
Copy link
Contributor

@Alkarex Alkarex commented Mar 20, 2021

Fix

PHP Fatal error:  Uncaught ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty in /SimplePie/Locator.php:83

set_error_handler does not catch ValueError in PHP8.
The patch is compatible PHP5 and PHP7.

Fix downstream bug FreshRSS/FreshRSS#3537
Downstream PR FreshRSS/FreshRSS#3547

Fix
```
PHP Fatal error:  Uncaught ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty in /SimplePie/Locator.php:83
```

`set_error_handler` does not catch ValueError in PHP8
The code is compatible PHP5 and PHP7.

Fix downstream bug FreshRSS/FreshRSS#3537
Downstream PR FreshRSS/FreshRSS#3547
$this->curl_options = $curl_options;

if (class_exists('DOMDocument'))
if (class_exists('DOMDocument') && $this->file->body != '')

Choose a reason for hiding this comment

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

Wouldn't it be better to use the empty() function? Can it be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

loadHTML() will raise an error if the input is null or empty. This test covers both.

Choose a reason for hiding this comment

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

Oh yeh, "type juggling".

{
$this->dom->loadHTML($this->file->body);
}
catch (Throwable $ex)

Choose a reason for hiding this comment

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

Is this needed or is it more better safe than sorry?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are potentially other errors than just empty input. For this specific bug, using either the null/empty test or the catch is sufficient. The catch is to more specifically extend the set_error_handler.

@mblaney mblaney merged commit 2b41433 into simplepie:master Mar 23, 2021
@Alkarex Alkarex deleted the PHP8-catch-ValueError branch March 23, 2021 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants