Fix parsing invalid href

See https://github.com/oscarotero/Embed/pull/502
This commit is contained in:
grandeljay 2022-10-10 13:01:23 +02:00
parent f839fb1077
commit d29a853be1
2 changed files with 25 additions and 1 deletions

View file

@ -3,6 +3,8 @@ declare(strict_types = 1);
namespace Embed\Detectors;
use function Embed\isEmpty;
class Languages extends Detector
{
/**
@ -17,7 +19,7 @@ class Languages extends Detector
$language = $node->getAttribute('hreflang');
$href = $node->getAttribute('href');
if (!$language || !$href) {
if (isEmpty($language, $href)) {
continue;
}

View file

@ -132,3 +132,25 @@ function getDirectory(string $path, int $position): ?string
$dirs = explode('/', $path);
return $dirs[$position + 1] ?? null;
}
/**
* Determine whether at least one of the supplied variables is empty.
*
* @param mixed ...$values The values to check.
*
* @return boolean
*/
function isEmpty(mixed ...$values): bool
{
$skipValues = array(
'undefined',
);
foreach ($values as $value) {
if (empty($value) || in_array($value, $skipValues)) {
return true;
}
}
return false;
}