Skip to content

Commit 6f3bf08

Browse files
committed
Fixed wrong HTML detection on PHP 8.4
1 parent 49c5e86 commit 6f3bf08

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/types/src/Flow/Types/Type/Native/String/StringTypeChecker.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ public function isHTML() : bool
126126
$options |= constant('\Dom\HTML_NO_DEFAULT_NS');
127127
}
128128

129-
HTMLDocument::createFromString($this->string, $options);
130-
} elseif (\preg_match('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im', $this->string) === 1) {
129+
$doc = HTMLDocument::createFromString($this->string, $options);
130+
131+
return $doc->saveHtml() === $this->string;
132+
}
133+
134+
if (\preg_match('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im', $this->string) === 1) {
131135
try {
132136
\libxml_use_internal_errors(true);
133137

src/lib/types/tests/Flow/Types/Tests/Unit/Value/HTMLDocumentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ final class HTMLDocumentTest extends TestCase
1414
#[RequiresPhp('>= 8.4')]
1515
public function test_create_with_dom_document_html_on_newer() : void
1616
{
17-
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>');
17+
$doc = \Dom\HTMLDocument::createFromString('<html><body><div><span>bar</span></div></body></html>', \LIBXML_HTML_NOIMPLIED);
1818

1919
$document = new HTMLDocument($doc);
2020

21-
self::assertSame('<html><head></head><body><div><span>bar</span></div></body></html>', (string) $document);
21+
self::assertSame('<html><body><div><span>bar</span></div></body></html>', (string) $document);
2222
}
2323

2424
#[RequiresPhp('<= 8.4')]

0 commit comments

Comments
 (0)