Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing invalid href #502

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Detectors/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Embed\Detectors;

use function Embed\isEmpty;

class Languages extends Detector
{
/**
Expand All @@ -17,7 +19,7 @@ public function detect(): array
$language = $node->getAttribute('hreflang');
$href = $node->getAttribute('href');

if (!$language || !$href) {
if (isEmpty($language, $href)) {
continue;
}

Expand Down
22 changes: 22 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}