File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed
src/Flow/Types/Type/Native/String
tests/Flow/Types/Tests/Unit/Value Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -119,15 +119,19 @@ public function isHTML() : bool
119119 return false ;
120120 }
121121
122- if (\class_exists ('\Dom\HTMLDocument ' , false )) {
123- $ options = \LIBXML_HTML_NOIMPLIED ;
122+ if (\preg_match ('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im ' , $ this ->string ) === 1 ) {
123+ if (\class_exists ('\Dom\HTMLDocument ' , false )) {
124+ $ options = \LIBXML_HTML_NOIMPLIED ;
124125
125- if (defined ('Dom\HTML_NO_DEFAULT_NS ' )) {
126- $ options |= constant ('\Dom\HTML_NO_DEFAULT_NS ' );
126+ if (defined ('Dom\HTML_NO_DEFAULT_NS ' )) {
127+ $ options |= constant ('\Dom\HTML_NO_DEFAULT_NS ' );
128+ }
129+
130+ $ doc = @HTMLDocument::createFromString ($ this ->string , $ options );
131+
132+ return $ doc ->saveHtml () === $ this ->string ;
127133 }
128134
129- HTMLDocument::createFromString ($ this ->string , $ options );
130- } elseif (\preg_match ('/(<!doctype(.+?)>)?<html(.+?)>(.+?)<\/html>/im ' , $ this ->string ) === 1 ) {
131135 try {
132136 \libxml_use_internal_errors (true );
133137
Original file line number Diff line number Diff 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 ' )]
You can’t perform that action at this time.
0 commit comments