Skip to content

Commit 410780d

Browse files
Don’t call libxml_disable_entity_loader() on recent libxml
Since libxml 2.9.0, entity substitution is disabled by default and can only be enabled by passing LIBXML_NOENT with the parse call (e.g. DOMDocument::loadHTML()). Since we don’t pass LIBXML_NOENT, it’s safe for us to skip the libxml_disable_entity_loader() call on libxml versions newer than that, which is good, because the function was deprecated in PHP 8. References: PHP.Watch [1] and PHP pull request #5867 [2]. (The function documentation [3] doesn’t explain this very clearly, in my opinion.) [1]: https://php.watch/versions/8.0/libxml_disable_entity_loader-deprecation [2]: https://github.com/php/php-src/pull/5867/files [3]: https://www.php.net/manual/en/function.libxml-disable-entity-loader.php
1 parent 4565462 commit 410780d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Component.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public function render( array $data ) {
6767
* @return DOMDocument
6868
*/
6969
private function parseHtml( $html ) {
70-
$entityLoaderDisabled = libxml_disable_entity_loader( true );
70+
if ( LIBXML_VERSION < 20900 ) {
71+
$entityLoaderDisabled = libxml_disable_entity_loader( true );
72+
}
7173
$internalErrors = libxml_use_internal_errors( true );
7274
$document = new DOMDocument( '1.0', 'UTF-8' );
7375

@@ -84,7 +86,9 @@ private function parseHtml( $html ) {
8486

8587
// Restore previous state
8688
libxml_use_internal_errors( $internalErrors );
87-
libxml_disable_entity_loader( $entityLoaderDisabled );
89+
if ( LIBXML_VERSION < 20900 ) {
90+
libxml_disable_entity_loader( $entityLoaderDisabled );
91+
}
8892

8993
foreach ( $errors as $error ) {
9094
//TODO html5 tags can fail parsing

0 commit comments

Comments
 (0)