ezyang / htmlpurifier

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

fix: Remove unnecessary disablement of autoload in `class_exists` usage #364

Closed stevebauman closed 1 year ago

stevebauman commented 1 year ago

This PR removes the usage of the secondary argument in class_exists() checks in HTML Purifier. This secondary argument is being used to disable autoloading the class if it has not yet been autoloaded.

The current implementation breaks composer based projects where a class may not have been included or required yet via composers autoloader, but has been registered as a definition cache:

$cache = \App\Purifier\RemoteFilesystemDefinition::class;

HTMLPurifier_DefinitionCacheFactory::instance()->register($cache, $cache);

$htmlConfig = HTMLPurifier_Config::create($config);

$htmlConfig->set('Cache.DefinitionImpl', $cache);

Upon usage:

ErrorException : Unrecognized DefinitionCache App\Purifier\RemoteFilesystemDefinition, using Serializer instead

This exception can be resolved by require'ing or include'ing the class manually, or via a spl_autoload_call($cache):

$cache = \App\Purifier\RemoteFilesystemDefinition::class;

spl_autoload_call($cache);

HTMLPurifier_DefinitionCacheFactory::instance()->register($cache, $cache);

However, this should not be necessary in todays PHP, as class strings are frequently used as a way to dynamically register implementations of things, and removing the secondary argument in class_exists() results in the definition cache being properly registered and used.

binaryfire commented 10 months ago

Hi @ezyang. Would it be possible to tag a new release which includes this fix?

github-actions[bot] commented 7 months ago

:tada: This PR is included in version 4.17.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: