From 70a7a3f5dd5970a3bb957f01265567249795f303 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 10 Mar 2010 00:58:37 -0500 Subject: [PATCH] Handle
      properly by adding missing
    1. tag. Signed-off-by: Edward Z. Yang --- NEWS | 1 + library/HTMLPurifier/ElementDef.php | 7 +++++++ library/HTMLPurifier/HTMLModule/List.php | 6 ++++-- library/HTMLPurifier/Strategy/MakeWellFormed.php | 13 +++++++++++++ tests/HTMLPurifier/Strategy/MakeWellFormedTest.php | 21 +++++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 3f058881..560825cd 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Support flashvars when using %HTML.SafeObject ! Support for Internet Explorer compatibility with %HTML.SafeObject using %Output.FlashCompat. +! Handle
          properly, by inserting the necessary
        1. tag. 4.0.0, released 2009-07-07 # APIs for ConfigSchema subsystem have substantially changed. See diff --git a/library/HTMLPurifier/ElementDef.php b/library/HTMLPurifier/ElementDef.php index aede2c3b..5498d956 100644 --- a/library/HTMLPurifier/ElementDef.php +++ b/library/HTMLPurifier/ElementDef.php @@ -98,6 +98,13 @@ class HTMLPurifier_ElementDef public $autoclose = array(); /** + * If a foreign element is found in this element, test if it is + * allowed by this sub-element; if it is, instead of closing the + * current element, place it inside this element. + */ + public $wrap; + + /** * Whether or not this is a formatting element affected by the * "Active Formatting Elements" algorithm. */ diff --git a/library/HTMLPurifier/HTMLModule/List.php b/library/HTMLPurifier/HTMLModule/List.php index 1d15f272..74d4522f 100644 --- a/library/HTMLPurifier/HTMLModule/List.php +++ b/library/HTMLPurifier/HTMLModule/List.php @@ -20,8 +20,10 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule public $content_sets = array('Flow' => 'List'); public function setup($config) { - $this->addElement('ol', 'List', 'Required: li', 'Common'); - $this->addElement('ul', 'List', 'Required: li', 'Common'); + $ol = $this->addElement('ol', 'List', 'Required: li', 'Common'); + $ol->wrap = "li"; + $ul = $this->addElement('ul', 'List', 'Required: li', 'Common'); + $ul->wrap = "li"; $this->addElement('dl', 'List', 'Required: dt | dd', 'Common'); $this->addElement('li', false, 'Flow', 'Common'); diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index ef0796e0..316b2386 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -220,6 +220,19 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $autoclose = false; } + if ($autoclose && $definition->info[$token->name]->wrap) { + // check if this is actually a wrap (mmm wraps!) + $wrapname = $definition->info[$token->name]->wrap; + $wrapdef = $definition->info[$wrapname]; + $elements = $wrapdef->child->getAllowedElements($config); + if (isset($elements[$token->name])) { + $newtoken = new HTMLPurifier_Token_Start($wrapname); + $this->insertBefore($newtoken); + $reprocess = true; + continue; + } + } + $carryover = false; if ($autoclose && $definition->info[$parent->name]->formatting) { $carryover = true; diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php index 0f96c49b..b7f17640 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php @@ -116,6 +116,27 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn ); } + function testNestedOl() { + $this->assertResult( + '
            ', + '
              ' + ); + } + + function testNestedUl() { + $this->assertResult( + '
                ', + '
                  ' + ); + } + + function testNestedOlWithStrangeEnding() { + $this->assertResult( + '
                      1. foo
                    1. foo
                    ', + '
                        1. foo
                      1. foo
                    ' + ); + } + } // vim: et sw=4 sts=4 -- 2.11.4.GIT