mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Rewrite FixNesting implementation to be tree-based.
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>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Defines allowed child nodes and validates tokens against it.
|
||||
* Defines allowed child nodes and validates nodes against it.
|
||||
*/
|
||||
abstract class HTMLPurifier_ChildDef
|
||||
{
|
||||
@@ -41,12 +41,12 @@ abstract class HTMLPurifier_ChildDef
|
||||
/**
|
||||
* Validates nodes according to definition and returns modification.
|
||||
*
|
||||
* @param HTMLPurifier_Token[] $tokens_of_children Array of HTMLPurifier_Token
|
||||
* @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 child tokens
|
||||
* @return bool|array true to leave nodes as is, false to remove parent node, array of replacement children
|
||||
*/
|
||||
abstract public function validateChildren($tokens_of_children, $config, $context);
|
||||
abstract public function validateChildren($children, $config, $context);
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
Reference in New Issue
Block a user