Skip to content

Commit e914760

Browse files
committed
Allow reading not strictly valid HTML
1 parent 3c48153 commit e914760

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/core/etl/src/Flow/ETL/Row/Entry/HTMLEntry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(
3232
?Metadata $metadata = null,
3333
) {
3434
if (\is_string($value)) {
35-
$this->value = HTMLDocument::createFromString($value);
35+
$this->value = HTMLDocument::createFromString($value, \LIBXML_NOERROR);
3636
} else {
3737
$this->value = $value;
3838
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Entry/HTMLEntryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,24 @@ public function test_renames_entry() : void
166166
self::assertEquals($entry->type(), $newEntry->type());
167167
}
168168

169+
public function test_with_non_fully_valid_html_string() : void
170+
{
171+
$html = <<<'HTML'
172+
<!DOCTYPE html>
173+
<html lang="en">
174+
<head></head>
175+
<body>
176+
<div>foo</div>
177+
<div><p><span>bar</span></span></p></div>
178+
</body>
179+
</html>
180+
HTML;
181+
$entry = html_entry('html', $html);
182+
183+
// Not equals as HTMLDocument removed unexpected close of span tag
184+
self::assertNotEquals($html, $entry->toString());
185+
}
186+
169187
public function test_with_value() : void
170188
{
171189
$entry = html_entry('html', '<!DOCTYPE html><html lang="en"><head></head><body><div>foobar</div></body></html>');

src/lib/types/src/Flow/Types/Type/Logical/HTMLType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function cast(mixed $value) : HTMLDocument
4040

4141
/* @phpstan-ignore-next-line */
4242
if (\is_string($value)) {
43-
return HTMLDocument::createFromString($value);
43+
return HTMLDocument::createFromString($value, \LIBXML_NOERROR);
4444
}
4545

4646
return $value;

0 commit comments

Comments
 (0)