From 087145a71b28b05f23141555bf5d4d3a4ae2d310 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 27 Oct 2012 02:32:48 -0700 Subject: [PATCH] Blacklist more tags from RemoveEmpty. Signed-off-by: Edward Z. Yang --- NEWS | 1 + library/HTMLPurifier/Injector/RemoveEmpty.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ee0511cc..cfcfc97f 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fix bug with non lower-case color names in HTML - Fix bug where data URI validation doesn't remove temporary files. Thanks Javier MarĂ­n Ros for reporting. +- Don't remove certain empty tags on RemoveEmpty. 4.4.0, released 2012-01-18 # Removed PEARSax3 handler. diff --git a/library/HTMLPurifier/Injector/RemoveEmpty.php b/library/HTMLPurifier/Injector/RemoveEmpty.php index 638bfca0..423f079e 100644 --- a/library/HTMLPurifier/Injector/RemoveEmpty.php +++ b/library/HTMLPurifier/Injector/RemoveEmpty.php @@ -5,6 +5,9 @@ class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector private $context, $config, $attrValidator, $removeNbsp, $removeNbspExceptions; + // TODO: make me configurable + private $_exclude = array('colgroup' => 1, 'th' => 1, 'td' => 1, 'iframe' => 1); + public function prepare($config, $context) { parent::prepare($config, $context); $this->config = $config; @@ -30,7 +33,7 @@ class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector break; } if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) { - if ($token->name == 'colgroup') return; + if (isset($this->_exclude[$token->name])) return; $this->attrValidator->validateToken($token, $this->config, $this->context); $token->armor['ValidateAttributes'] = true; if (isset($token->attr['id']) || isset($token->attr['name'])) return;