@@ -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