mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
0767bbc12d
This mega-patch rips out the FixNesting implementation and the related ChildDef components. The primary algorithmic change is to convert from use of tokens to tree nodes, which are far more amenable to the style of processing that FixNesting uses. Additionally, FixNesting has been changed to go bottom-up rather than top-down, in order to avoid needing to implement backtracking. This patch simplifies a good deal of the relevant logic, since we no longer need to continually recalculate the nesting structure when processing things. However, the conversion to the alternate format incurs some overhead, so for small inputs these changes are not a win. One possibility to greatly reduce the constant factors here is to switch to entirely using libxml's representation, and never serializing tokens; this would require one to rewrite injectors, however. The iterative post-order traversal in FixNesting is a bit subtle, but we have essentially reified the stack and continuations. We've removed support for %Core.EscapeInvalidChildren. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Defines allowed child nodes and validates nodes against it.
|
|
*/
|
|
abstract class HTMLPurifier_ChildDef
|
|
{
|
|
/**
|
|
* Type of child definition, usually right-most part of class name lowercase.
|
|
* Used occasionally in terms of context.
|
|
* @type string
|
|
*/
|
|
public $type;
|
|
|
|
/**
|
|
* Indicates whether or not an empty array of children is okay.
|
|
*
|
|
* This is necessary for redundant checking when changes affecting
|
|
* a child node may cause a parent node to now be disallowed.
|
|
* @type bool
|
|
*/
|
|
public $allow_empty;
|
|
|
|
/**
|
|
* Lookup array of all elements that this definition could possibly allow.
|
|
* @type array
|
|
*/
|
|
public $elements = array();
|
|
|
|
/**
|
|
* Get lookup of tag names that should not close this element automatically.
|
|
* All other elements will do so.
|
|
* @param HTMLPurifier_Config $config HTMLPurifier_Config object
|
|
* @return array
|
|
*/
|
|
public function getAllowedElements($config)
|
|
{
|
|
return $this->elements;
|
|
}
|
|
|
|
/**
|
|
* Validates nodes according to definition and returns modification.
|
|
*
|
|
* @param HTMLPurifier_Node[] $children Array of HTMLPurifier_Node
|
|
* @param HTMLPurifier_Config $config HTMLPurifier_Config object
|
|
* @param HTMLPurifier_Context $context HTMLPurifier_Context object
|
|
* @return bool|array true to leave nodes as is, false to remove parent node, array of replacement children
|
|
*/
|
|
abstract public function validateChildren($children, $config, $context);
|
|
}
|
|
|
|
// vim: et sw=4 sts=4
|