Skip to content

Commit 17b892c

Browse files
authored
Merge pull request #502 from grandeljay/fix-parsing-invalid-href
Fix parsing invalid href
2 parents 88b7c05 + d2ea064 commit 17b892c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Detectors/Languages.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Embed\Detectors;
55

6+
use function Embed\isEmpty;
7+
68
class Languages extends Detector
79
{
810
/**
@@ -17,7 +19,7 @@ public function detect(): array
1719
$language = $node->getAttribute('hreflang');
1820
$href = $node->getAttribute('href');
1921

20-
if (!$language || !$href) {
22+
if (isEmpty($language, $href)) {
2123
continue;
2224
}
2325

src/functions.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,25 @@ function getDirectory(string $path, int $position): ?string
132132
$dirs = explode('/', $path);
133133
return $dirs[$position + 1] ?? null;
134134
}
135+
136+
/**
137+
* Determine whether at least one of the supplied variables is empty.
138+
*
139+
* @param mixed ...$values The values to check.
140+
*
141+
* @return boolean
142+
*/
143+
function isEmpty(mixed ...$values): bool
144+
{
145+
$skipValues = array(
146+
'undefined',
147+
);
148+
149+
foreach ($values as $value) {
150+
if (empty($value) || in_array($value, $skipValues)) {
151+
return true;
152+
}
153+
}
154+
155+
return false;
156+
}

0 commit comments

Comments
 (0)