[core] Fix XPathAbstract while working around Simple HTML DOM bug (#3408)

This commit is contained in:
mrnoname1000 2023-05-21 14:06:35 -05:00 committed by GitHub
parent f803ffa79a
commit 87b9f2dd94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 6 deletions

View File

@ -187,13 +187,24 @@ function defaultLinkTo($dom, $url)
// Use long method names for compatibility with simple_html_dom and DOMDocument // Use long method names for compatibility with simple_html_dom and DOMDocument
// foreach ($dom->getElementsByTagName('img', null) as $image) { // Work around bug in simple_html_dom->getElementsByTagName
// $image->setAttribute('src', urljoin($url, $image->getAttribute('src'))); if ($dom instanceof simple_html_dom) {
// } $findByTag = function ($name) use ($dom) {
return $dom->getElementsByTagName($name, null);
};
} else {
$findByTag = function ($name) use ($dom) {
return $dom->getElementsByTagName($name);
};
}
// foreach ($dom->getElementsByTagName('a', null) as $anchor) { foreach ($findByTag('img') as $image) {
// $anchor->setAttribute('href', urljoin($url, $anchor->getAttribute('href'))); $image->setAttribute('src', urljoin($url, $image->getAttribute('src')));
// } }
foreach ($findByTag('a') as $anchor) {
$anchor->setAttribute('href', urljoin($url, $anchor->getAttribute('href')));
}
// Will never be true for DOMDocument // Will never be true for DOMDocument
if ($string_convert) { if ($string_convert) {