HTMLPurifier label tag support

Viewed 302

I can't make <label> tag recognizable by HTMLPurifier.

Running

$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'label');
$purifier = new HTMLPurifier($config);
echo $purifier->purify("<label>Link</label>");

Throws Warning: Element 'label' is not supported (for information on implementing this, see the support forums).

Also no luck using addElement()

$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.DefinitionID', 'test');
$config->set('HTML.DefinitionRev', 1);
if ($def = $config->maybeGetRawHTMLDefinition()) {
   $def->addElement('label', 'Block', 'Inline', 'Common', array());
}
$purifier = new HTMLPurifier($config);
echo $purifier->purify("<label>Link</label>");

Still returns just Link, where I expect <label>Link</label>. Any thoughts?

Update: Using $config->set('HTML.Trusted', true); does the difference, but it disables XSS protection. Not an option for me.

1 Answers

After changing configuration, you need to make sure to clean cache in vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/ or temporary disable caching using

$config->set('Cache.DefinitionImpl', null);

If you use $config->set('HTML.Allowed', 'h1,h2,...'); you also need to add label there.

Related