From f9e73fb49a762c367c2f110878ddb1fedd2b2e0b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 27 Mar 2026 20:29:09 +0100 Subject: [PATCH 1/2] Fix bad encoding for `tidy_repair_string` Tidy on PHP 8.5 is more restrictive on what can be given as input encoding. Before, it worked as an unknown value was converted to `utf8`. --- src/Readability.php | 6 +++--- tests/ReadabilityTest.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Readability.php b/src/Readability.php index c4ea980..cf823f2 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -88,7 +88,7 @@ class Readability implements LoggerAwareInterface 'enclose-text' => true, 'merge-divs' => true, // 'merge-spans' => true, - 'input-encoding' => '????', + 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'hide-comments' => true, ]; @@ -1118,7 +1118,7 @@ class Readability implements LoggerAwareInterface $topCandidates = array_filter( $topCandidates, - fn ($v, $idx) => 0 === $idx || null !== $v, + static fn ($v, $idx) => 0 === $idx || null !== $v, \ARRAY_FILTER_USE_BOTH ); $topCandidate = $topCandidates[0]; @@ -1481,7 +1481,7 @@ class Readability implements LoggerAwareInterface private function hasSingleTagInsideElement(\DOMElement $node, string $tag): bool { $childNodes = iterator_to_array($node->childNodes); - $children = array_filter($childNodes, fn ($childNode) => $childNode instanceof \DOMElement); + $children = array_filter($childNodes, static fn ($childNode) => $childNode instanceof \DOMElement); // There should be exactly 1 element child with given tag if (1 !== \count($children) || $children[0]->nodeName !== $tag) { diff --git a/tests/ReadabilityTest.php b/tests/ReadabilityTest.php index e38b2e9..e93efb0 100644 --- a/tests/ReadabilityTest.php +++ b/tests/ReadabilityTest.php @@ -21,6 +21,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase public function testConstructDefault(): void { $readability = $this->getReadability(''); + $this->assertSame('utf8', $readability->tidy_config['input-encoding']); $readability->init(); $this->assertNull($readability->url); @@ -323,7 +324,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase $oldErrorReporting = error_reporting(\E_ALL); $oldDisplayErrors = ini_set('display_errors', '1'); // dummy function to be used to the next test - set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline) { throw new \Exception($errstr, $errno); }); From 009b4ab9b8f7c39d62eb23af507b473d9485070f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 27 Mar 2026 20:31:52 +0100 Subject: [PATCH 2/2] Add PHP 8.5 on CI --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b233fbe..304521d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,6 +25,7 @@ jobs: - "8.2" - "8.3" - "8.4" + - "8.5" steps: - name: "Checkout"