Skip to content

Commit b33a405

Browse files
committed
Merge branch 'feat/invalid-html-head-elements' of github.com:vormkracht10/laravel-seo-scanner into feat/invalid-html-head-elements
2 parents a3595d5 + 55c4e41 commit b33a405

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Checks/Meta/InvalidHeadElementsCheck.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,24 @@ public function validateContent(Response $response): bool
5959
{
6060
// Get the raw HTML content from the response
6161
$html = $response->body();
62-
62+
6363
// Extract the head section using regex
6464
if (preg_match('/<head[^>]*>(.*?)<\/head>/is', $html, $matches)) {
6565
$headContent = $matches[1];
6666
} else {
6767
// No head section found
6868
$this->failureReason = __('failed.meta.invalid_head_elements.no_head');
6969
$this->actualValue = 'No head section found';
70+
7071
return false;
7172
}
7273

7374
// Extract all HTML tags from the head content, but exclude tags inside template elements
7475
$headTags = [];
75-
76+
7677
// First, remove template content to avoid detecting nested elements
7778
$headContentWithoutTemplates = preg_replace('/<template[^>]*>.*?<\/template>/is', '', $headContent);
78-
79+
7980
// Extract tags from the cleaned content
8081
preg_match_all('/<([a-zA-Z][a-zA-Z0-9]*)[^>]*>/i', $headContentWithoutTemplates, $matches);
8182
$headTags = $matches[1];
@@ -84,25 +85,27 @@ public function validateContent(Response $response): bool
8485
// No elements in head section
8586
$this->failureReason = __('failed.meta.invalid_head_elements.no_head');
8687
$this->actualValue = 'No head elements found';
88+
8789
return false;
8890
}
8991

9092
$invalidElements = [];
9193

9294
foreach ($headTags as $tagName) {
9395
$tagName = strtolower($tagName);
94-
96+
9597
// Check if the element is valid for the head section
96-
if (!in_array($tagName, $this->validHeadElements)) {
98+
if (! in_array($tagName, $this->validHeadElements)) {
9799
$invalidElements[] = $tagName;
98100
}
99101
}
100102

101-
if (!empty($invalidElements)) {
103+
if (! empty($invalidElements)) {
102104
$this->failureReason = __('failed.meta.invalid_head_elements.found', [
103-
'actualValue' => implode(', ', array_unique($invalidElements))
105+
'actualValue' => implode(', ', array_unique($invalidElements)),
104106
]);
105107
$this->actualValue = $invalidElements;
108+
106109
return false;
107110
}
108111

0 commit comments

Comments
 (0)