aboutsummaryrefslogtreecommitdiffstats
path: root/library/HTMLPurifier/Injector/RemoveEmpty.php
diff options
context:
space:
mode:
authorChristian Vogeley <christian.vogeley@hotmail.de>2015-01-11 16:22:59 +0100
committerChristian Vogeley <christian.vogeley@hotmail.de>2015-01-11 16:22:59 +0100
commitf0c7612bcd49d32e408e67ac1829ee891c677f7e (patch)
treed4cff4aa2d728524b631776ffffee71f42056421 /library/HTMLPurifier/Injector/RemoveEmpty.php
parent43f143a211c75138d09ceb89acc48ea7d5c31ca9 (diff)
parent10102ac2ac4d5b02012a9794e23656717ab05556 (diff)
downloadvolse-hubzilla-f0c7612bcd49d32e408e67ac1829ee891c677f7e.tar.gz
volse-hubzilla-f0c7612bcd49d32e408e67ac1829ee891c677f7e.tar.bz2
volse-hubzilla-f0c7612bcd49d32e408e67ac1829ee891c677f7e.zip
Merge remote-tracking branch 'upstream/master'
Conflicts: doc/html/classRedmatrix_1_1Import_1_1Import-members.html doc/html/classRedmatrix_1_1Import_1_1Import.js
Diffstat (limited to 'library/HTMLPurifier/Injector/RemoveEmpty.php')
-rw-r--r--library/HTMLPurifier/Injector/RemoveEmpty.php82
1 files changed, 66 insertions, 16 deletions
diff --git a/library/HTMLPurifier/Injector/RemoveEmpty.php b/library/HTMLPurifier/Injector/RemoveEmpty.php
index 638bfca03..cd885722e 100644
--- a/library/HTMLPurifier/Injector/RemoveEmpty.php
+++ b/library/HTMLPurifier/Injector/RemoveEmpty.php
@@ -2,10 +2,44 @@
class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
{
+ /**
+ * @type HTMLPurifier_Context
+ */
+ private $context;
- private $context, $config, $attrValidator, $removeNbsp, $removeNbspExceptions;
+ /**
+ * @type HTMLPurifier_Config
+ */
+ private $config;
- public function prepare($config, $context) {
+ /**
+ * @type HTMLPurifier_AttrValidator
+ */
+ private $attrValidator;
+
+ /**
+ * @type bool
+ */
+ private $removeNbsp;
+
+ /**
+ * @type bool
+ */
+ private $removeNbspExceptions;
+
+ /**
+ * @type array
+ * TODO: make me configurable
+ */
+ private $_exclude = array('colgroup' => 1, 'th' => 1, 'td' => 1, 'iframe' => 1);
+
+ /**
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return void
+ */
+ public function prepare($config, $context)
+ {
parent::prepare($config, $context);
$this->config = $config;
$this->context = $context;
@@ -14,38 +48,54 @@ class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
$this->attrValidator = new HTMLPurifier_AttrValidator();
}
- public function handleElement(&$token) {
- if (!$token instanceof HTMLPurifier_Token_Start) return;
+ /**
+ * @param HTMLPurifier_Token $token
+ */
+ public function handleElement(&$token)
+ {
+ if (!$token instanceof HTMLPurifier_Token_Start) {
+ return;
+ }
$next = false;
- for ($i = $this->inputIndex + 1, $c = count($this->inputTokens); $i < $c; $i++) {
- $next = $this->inputTokens[$i];
+ $deleted = 1; // the current tag
+ for ($i = count($this->inputZipper->back) - 1; $i >= 0; $i--, $deleted++) {
+ $next = $this->inputZipper->back[$i];
if ($next instanceof HTMLPurifier_Token_Text) {
- if ($next->is_whitespace) continue;
+ if ($next->is_whitespace) {
+ continue;
+ }
if ($this->removeNbsp && !isset($this->removeNbspExceptions[$token->name])) {
$plain = str_replace("\xC2\xA0", "", $next->data);
$isWsOrNbsp = $plain === '' || ctype_space($plain);
- if ($isWsOrNbsp) continue;
+ if ($isWsOrNbsp) {
+ continue;
+ }
}
}
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;
- $token = $i - $this->inputIndex + 1;
- for ($b = $this->inputIndex - 1; $b > 0; $b--) {
- $prev = $this->inputTokens[$b];
- if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) continue;
+ if (isset($token->attr['id']) || isset($token->attr['name'])) {
+ return;
+ }
+ $token = $deleted + 1;
+ for ($b = 0, $c = count($this->inputZipper->front); $b < $c; $b++) {
+ $prev = $this->inputZipper->front[$b];
+ if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) {
+ continue;
+ }
break;
}
// This is safe because we removed the token that triggered this.
- $this->rewind($b - 1);
+ $this->rewindOffset($b+$deleted);
return;
}
}
-
}
// vim: et sw=4 sts=4