Skip to content

Use PHP native html parsing (drops support for PHP < 8.4)#24

Merged
acoulton merged 4 commits into1.4.xfrom
1.4-native-table-parsing
Mar 10, 2026
Merged

Use PHP native html parsing (drops support for PHP < 8.4)#24
acoulton merged 4 commits into1.4.xfrom
1.4-native-table-parsing

Conversation

@acoulton
Copy link
Member

Updates our supported PHP versions so that we can use the native HTML5 parser in php >= 8.4 instead of having a dependency on masterminds/html5.

The original test data for this feature had invalid HTML (the `<time>` element was not actually in a cell).
When we switched to using masterminds/html5 for table parsing,
the parse error detection & handling was not updated.

This is partly because there are actually very few cases in
which input is actually *invalid* as html (as opposed to
being non-conformant, which isn't checked). And we did not
have test cases proving these examples.

Fixed the handling of this ahead of moving to native html
parsing in 1.4 (which is treated differently anyway).
We will be dropping support for older PHP versions, so that we can
(in the next commit) switch to using native html5 parsing instead
of having a masterminds/html5 dependency.
The newer native library would also allow us to refactor more
of the HTMLStringTableParser, but this would mean BC breaks
to our public API since the old code is written with protected
methods and non-final classes.
@acoulton acoulton force-pushed the 1.4-native-table-parsing branch from 5d5bc3c to 23b87f0 Compare March 10, 2026 12:06
@acoulton acoulton marked this pull request as ready for review March 10, 2026 12:08
@acoulton acoulton requested a review from craig410 March 10, 2026 12:08
sprintf("Expected html root element but got %s\n\n===HTML===\n%s", get_debug_type($table_elem), $html),
);
}
$table = \simplexml_import_dom($table_elem);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could in theory drop a bunch of the to/from simplexml stuff, the problem is we'd need a 2.0 release as the internal API of this class is all protected rather than private and the implementation expects to be passing simplexml nodes around.

There's a bigger set of tidying / refactoring we'd need to do for a 2.0 so I've gone with just the minimum to use the native parser without breaking BC.

@acoulton acoulton merged commit 5ab9e69 into 1.4.x Mar 10, 2026
2 checks passed
@acoulton acoulton deleted the 1.4-native-table-parsing branch March 10, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants