From 0680832d41d4d5377ea3ea8d8c10fd574d2deb7e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 21 May 2013 17:19:59 -0700 Subject: [PATCH] Use info_parent_def to get parent information, since it may not be present in info array. Signed-off-by: Edward Z. Yang --- NEWS | 2 ++ library/HTMLPurifier/Strategy/MakeWellFormed.php | 19 ++++++++----------- tests/HTMLPurifier/Injector/AutoParagraphTest.php | 5 +++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 130b14e7..f715f4f6 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier Michael Gusev for fixing. - Made Linkify URL parser a bit less permissive, so that non-breaking spaces and commas are not included as part of URL. Thanks nAS for fixing. +- Fix some bad interactions with %HTML.Allowed and injectors. Thanks + David Hirtz for reporting. 4.5.0, released 2013-02-17 # Fix bug where stacked attribute transforms clobber each other; diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index c7aa1bb8..53cd0db0 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -52,11 +52,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $generator = new HTMLPurifier_Generator($config, $context); $escape_invalid_tags = $config->get('Core.EscapeInvalidTags'); // used for autoclose early abortion - $global_parent_allowed_elements = array(); - if (isset($definition->info[$definition->info_parent])) { - // may be unset under testing circumstances - $global_parent_allowed_elements = $definition->info[$definition->info_parent]->child->getAllowedElements($config); - } + $global_parent_allowed_elements = $definition->info_parent_def->child->getAllowedElements($config); $e = $context->get('ErrorCollector', true); $t = false; // token index $i = false; // injector index @@ -241,11 +237,13 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $parent = array_pop($this->stack); $this->stack[] = $parent; + $parent_def = null; + $parent_elements = null; + $autoclose = false; if (isset($definition->info[$parent->name])) { - $elements = $definition->info[$parent->name]->child->getAllowedElements($config); - $autoclose = !isset($elements[$token->name]); - } else { - $autoclose = false; + $parent_def = $definition->info[$parent->name]; + $parent_elements = $parent_def->child->getAllowedElements($config); + $autoclose = !isset($parent_elements[$token->name]); } if ($autoclose && $definition->info[$token->name]->wrap) { @@ -255,7 +253,6 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $wrapname = $definition->info[$token->name]->wrap; $wrapdef = $definition->info[$wrapname]; $elements = $wrapdef->child->getAllowedElements($config); - $parent_elements = $definition->info[$parent->name]->child->getAllowedElements($config); if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) { $newtoken = new HTMLPurifier_Token_Start($wrapname); $this->insertBefore($newtoken); @@ -265,7 +262,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy } $carryover = false; - if ($autoclose && $definition->info[$parent->name]->formatting) { + if ($autoclose && $parent_def->formatting) { $carryover = true; } diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php index e6abbd1f..8f149011 100644 --- a/tests/HTMLPurifier/Injector/AutoParagraphTest.php +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -510,6 +510,11 @@ Bar", $this->assertResult('foobar'); } + function testParentElement() { + $this->config->set('HTML.Allowed', 'p,ul,li'); + $this->assertResult('Foo
  • Bar
', "

Foo

\n\n
  • Bar
"); + } + } // vim: et sw=4 sts=4 -- 2.11.4.GIT