ezyang / htmlpurifier

Standards compliant HTML filter written in PHP
http://htmlpurifier.org
GNU Lesser General Public License v2.1
3.07k stars 327 forks source link

Fix DOM Lexer for PHP versions older than 5.4 #225

Closed xemlock closed 5 years ago

xemlock commented 5 years ago

Hi @ezyang, I'd like to ask what's the current policy on supporting prehistoric PHP versions? The minimum PHP version in composer.json is set at 5.2, which is the reason I submit this PR.

The DOM Lexer (default lexer implementation) in version 4.11.0 does not work on PHP 5.3 because of this line.

Loading HTML document in PHP 5.3 fails with:

Fatal error: Call to a member function getElementsByTagName() on a non-object

After disabling (for the investigation purposes) muteErrorHandler we see the culprit:

Warning: DOMDocument::loadHTML() expects exactly 1 parameter, 2 given

According to the docs, second parameter to loadHTML requires at least PHP 5.4.

xemlock commented 5 years ago

@ezyang Can you restart failed jobs on Travis? Something got stuck:

$ phpenv global 5.5
rbenv: version `5.5' not installed
The command "phpenv global 5.5" failed and exited with 1 during .
Your build has been stopped.

Edit: Two builds failed because of https://travis-ci.community/t/php-5-4-and-5-5-archives-missing/3723

xemlock commented 5 years ago

@ezyang I rebased this PR with latest changes from master (fixed builds on Travis CI), so it's now mergeable.