Skip to content

Commit 235baf9

Browse files
committed
Do not set domainRegExp for local files
`parse_url($this->url, \PHP_URL_HOST)` will return `null` for local filesystem path. Casting it to `string` will produce an empty regular expression, which would match any link when computing link density. (cherry picked from commit c7208f6) This also fixes a warning since 1.x passes the `null` directly to `preg_replace` instead of explicitly casting it to `string`.
1 parent 487ce3a commit 235baf9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Readability.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,10 @@ private function loadHtml()
13961396
$this->logger->debug('Parsing URL: ' . $this->url);
13971397

13981398
if ($this->url) {
1399-
$this->domainRegExp = '/' . strtr(preg_replace('/www\d*\./', '', parse_url($this->url, \PHP_URL_HOST)), ['.' => '\.']) . '/';
1399+
$host = parse_url($this->url, \PHP_URL_HOST);
1400+
if (null !== $host) {
1401+
$this->domainRegExp = '/' . strtr(preg_replace('/www\d*\./', '', $host), ['.' => '\.']) . '/';
1402+
}
14001403
}
14011404

14021405
mb_internal_encoding('UTF-8');

0 commit comments

Comments
 (0)