Skip to content
Browse files

Handle <ol><ol> properly by adding missing <li> tag.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Loading branch information...
1 parent 4d612d5 commit 70a7a3f5dd5970a3bb957f01265567249795f303 @ezyang ezyang committed
View
1 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 <ol><ol> properly, by inserting the necessary <li> tag.
4.0.0, released 2009-07-07
# APIs for ConfigSchema subsystem have substantially changed. See
View
7 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.
*/
View
6 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');
View
13 library/HTMLPurifier/Strategy/MakeWellFormed.php
@@ -220,6 +220,19 @@ public function execute($tokens, $config, $context) {
$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;
View
21 tests/HTMLPurifier/Strategy/MakeWellFormedTest.php
@@ -116,6 +116,27 @@ function testInterleaved() {
);
}
+ function testNestedOl() {
+ $this->assertResult(
+ '<ol><ol></ol></ol>',
+ '<ol><li><ol></ol></li></ol>'
+ );
+ }
+
+ function testNestedUl() {
+ $this->assertResult(
+ '<ul><ul></ul></ul>',
+ '<ul><li><ul></ul></li></ul>'
+ );
+ }
+
+ function testNestedOlWithStrangeEnding() {
+ $this->assertResult(
+ '<ol><li><ol><ol><li>foo</li></ol></li><li>foo</li></ol>',
+ '<ol><li><ol><li><ol><li>foo</li></ol></li><li>foo</li></ol></li></ol>'
+ );
+ }
+
}
// vim: et sw=4 sts=4

0 comments on commit 70a7a3f

Please sign in to comment.
Something went wrong with that request. Please try again.