0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-20 12:31:53 +00:00

Use info_parent_def to get parent information, since it may not be present in info array.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2013-05-21 17:19:59 -07:00
parent 19360ddb36
commit 0680832d41
3 changed files with 15 additions and 11 deletions

2
NEWS
View File

@ -15,6 +15,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
Michael Gusev <mgusev@sugarcrm.com> for fixing. Michael Gusev <mgusev@sugarcrm.com> for fixing.
- Made Linkify URL parser a bit less permissive, so that non-breaking - 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. 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 4.5.0, released 2013-02-17
# Fix bug where stacked attribute transforms clobber each other; # Fix bug where stacked attribute transforms clobber each other;

View File

@ -52,11 +52,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
$generator = new HTMLPurifier_Generator($config, $context); $generator = new HTMLPurifier_Generator($config, $context);
$escape_invalid_tags = $config->get('Core.EscapeInvalidTags'); $escape_invalid_tags = $config->get('Core.EscapeInvalidTags');
// used for autoclose early abortion // used for autoclose early abortion
$global_parent_allowed_elements = array(); $global_parent_allowed_elements = $definition->info_parent_def->child->getAllowedElements($config);
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);
}
$e = $context->get('ErrorCollector', true); $e = $context->get('ErrorCollector', true);
$t = false; // token index $t = false; // token index
$i = false; // injector index $i = false; // injector index
@ -241,11 +237,13 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
$parent = array_pop($this->stack); $parent = array_pop($this->stack);
$this->stack[] = $parent; $this->stack[] = $parent;
if (isset($definition->info[$parent->name])) { $parent_def = null;
$elements = $definition->info[$parent->name]->child->getAllowedElements($config); $parent_elements = null;
$autoclose = !isset($elements[$token->name]);
} else {
$autoclose = false; $autoclose = false;
if (isset($definition->info[$parent->name])) {
$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) { if ($autoclose && $definition->info[$token->name]->wrap) {
@ -255,7 +253,6 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
$wrapname = $definition->info[$token->name]->wrap; $wrapname = $definition->info[$token->name]->wrap;
$wrapdef = $definition->info[$wrapname]; $wrapdef = $definition->info[$wrapname];
$elements = $wrapdef->child->getAllowedElements($config); $elements = $wrapdef->child->getAllowedElements($config);
$parent_elements = $definition->info[$parent->name]->child->getAllowedElements($config);
if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) { if (isset($elements[$token->name]) && isset($parent_elements[$wrapname])) {
$newtoken = new HTMLPurifier_Token_Start($wrapname); $newtoken = new HTMLPurifier_Token_Start($wrapname);
$this->insertBefore($newtoken); $this->insertBefore($newtoken);
@ -265,7 +262,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
} }
$carryover = false; $carryover = false;
if ($autoclose && $definition->info[$parent->name]->formatting) { if ($autoclose && $parent_def->formatting) {
$carryover = true; $carryover = true;
} }

View File

@ -510,6 +510,11 @@ Bar</div>",
$this->assertResult('<b>foobar</b>'); $this->assertResult('<b>foobar</b>');
} }
function testParentElement() {
$this->config->set('HTML.Allowed', 'p,ul,li');
$this->assertResult('Foo<ul><li>Bar</li></ul>', "<p>Foo</p>\n\n<ul><li>Bar</li></ul>");
}
} }
// vim: et sw=4 sts=4 // vim: et sw=4 sts=4