mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
[1.5.0] Implement Legacy module.
- Yet another test EnableAttrID - ElementDef now is mindful of attr inclusion merges git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@732 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -93,7 +93,17 @@ class HTMLPurifier_ElementDef
|
||||
function mergeIn($def) {
|
||||
|
||||
// later keys takes precedence
|
||||
foreach($def->attr as $k => $v) $this->attr[$k] = $v;
|
||||
foreach($def->attr as $k => $v) {
|
||||
if ($k == 0) {
|
||||
// merge in the includes
|
||||
// sorry, no way to override an include
|
||||
foreach ($v as $v2) {
|
||||
$def->attr[0][] = $v2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$this->attr[$k] = $v;
|
||||
}
|
||||
foreach($def->attr_transform_pre as $k => $v) $this->attr_transform_pre[$k] = $v;
|
||||
foreach($def->attr_transform_post as $k => $v) $this->attr_transform_post[$k] = $v;
|
||||
foreach($def->auto_close as $k => $v) $this->auto_close[$k] = $v;
|
||||
|
@@ -36,6 +36,7 @@ require_once 'HTMLPurifier/HTMLModule/StyleAttribute.php';
|
||||
|
||||
// compat modules
|
||||
require_once 'HTMLPurifier/HTMLModule/TransformToStrict.php';
|
||||
require_once 'HTMLPurifier/HTMLModule/Legacy.php';
|
||||
|
||||
HTMLPurifier_ConfigSchema::define(
|
||||
'HTML', 'EnableAttrID', false, 'bool',
|
||||
@@ -256,6 +257,7 @@ class HTMLPurifier_HTMLDefinition
|
||||
$this->modules['StyleAttribute']= new HTMLPurifier_HTMLModule_StyleAttribute();
|
||||
|
||||
$this->modules['TransformToStrict'] = new HTMLPurifier_HTMLModule_TransformToStrict($config);
|
||||
if (!$this->strict) $this->modules['Legacy'] = new HTMLPurifier_HTMLModule_Legacy($config);
|
||||
|
||||
$this->attr_types = new HTMLPurifier_AttrTypes();
|
||||
$this->attr_collections = new HTMLPurifier_AttrCollections();
|
||||
@@ -393,42 +395,6 @@ class HTMLPurifier_HTMLDefinition
|
||||
*/
|
||||
function setupCompat($config) {
|
||||
|
||||
// convenience for compat
|
||||
$e_Inline = new HTMLPurifier_ChildDef_Optional(
|
||||
$this->info_content_sets['Inline'] +
|
||||
array('#PCDATA' => true));
|
||||
|
||||
// blockquote alt child def, implement in Legacy
|
||||
if (!$this->strict) {
|
||||
$this->info['blockquote']->child =
|
||||
new HTMLPurifier_ChildDef_Optional(
|
||||
$this->info_content_sets['Flow'] +
|
||||
array('#PCDATA' => true));
|
||||
}
|
||||
|
||||
// deprecated element definitions, implement in Legacy
|
||||
if (!$this->strict) {
|
||||
$this->info['u'] =
|
||||
$this->info['s'] =
|
||||
$this->info['strike'] = new HTMLPurifier_ElementDef();
|
||||
$this->info['u']->child =
|
||||
$this->info['s']->child =
|
||||
$this->info['strike']->child = $e_Inline;
|
||||
$this->info['u']->descendants_are_inline =
|
||||
$this->info['s']->descendants_are_inline =
|
||||
$this->info['strike']->descendants_are_inline = true;
|
||||
}
|
||||
|
||||
// changed content model for loose, implement in Legacy
|
||||
if ($this->strict) {
|
||||
$this->info['address']->child = $e_Inline;
|
||||
} else {
|
||||
$this->info['address']->child =
|
||||
new HTMLPurifier_ChildDef_Optional(
|
||||
$this->info_content_sets['Inline'] +
|
||||
array('#PCDATA' => true, 'p' => true));
|
||||
}
|
||||
|
||||
// deprecated config setting, implement in DisableURI module
|
||||
if ($config->get('Attr', 'DisableURI')) {
|
||||
$this->info['a']->attr['href'] =
|
||||
@@ -440,12 +406,6 @@ class HTMLPurifier_HTMLDefinition
|
||||
$this->info['img']->attr['src'] = null;
|
||||
}
|
||||
|
||||
// deprecated attributes implementations, implement in Legacy
|
||||
if (!$this->strict) {
|
||||
$this->info['li']->attr['value'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$this->info['ol']->attr['start'] = new HTMLPurifier_AttrDef_Integer();
|
||||
}
|
||||
|
||||
// setup allowed elements, SubtractiveWhitelist module
|
||||
$allowed_elements = $config->get('HTML', 'AllowedElements');
|
||||
if (is_array($allowed_elements)) {
|
||||
|
@@ -17,7 +17,40 @@
|
||||
class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
// unimplemented
|
||||
// incomplete
|
||||
|
||||
var $elements = array('u', 's', 'strike');
|
||||
var $non_standalone_elements = array('li', 'ol', 'address', 'blockquote');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Legacy() {
|
||||
// setup new elements
|
||||
foreach ($this->elements as $name) {
|
||||
$this->info[$name] = new HTMLPurifier_ElementDef();
|
||||
// for u, s, strike, as more elements get added, add
|
||||
// conditionals as necessary
|
||||
$this->info[$name]->content_model = 'Inline | #PCDATA';
|
||||
$this->info[$name]->content_model_type = 'optional';
|
||||
$this->info[$name]->attr[0] = array('Common');
|
||||
}
|
||||
|
||||
// setup modifications to old elements
|
||||
foreach ($this->non_standalone_elements as $name) {
|
||||
$this->info[$name] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$name]->standalone = false;
|
||||
}
|
||||
|
||||
$this->info['li']->attr['value'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$this->info['ol']->attr['start'] = new HTMLPurifier_AttrDef_Integer();
|
||||
|
||||
$this->info['address']->content_model = 'Inline | #PCDATA | p';
|
||||
$this->info['address']->content_model_type = 'optional';
|
||||
$this->info['address']->child = false;
|
||||
|
||||
$this->info['blockquote']->content_model = 'Flow | #PCDATA';
|
||||
$this->info['blockquote']->content_model_type = 'optional';
|
||||
$this->info['blockquote']->child = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -83,6 +83,20 @@ class HTMLPurifier_Test extends UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
function testEnableAttrID() {
|
||||
|
||||
$this->purifier = new HTMLPurifier();
|
||||
|
||||
$this->assertPurification(
|
||||
'<span id="moon">foobar</span>',
|
||||
'<span>foobar</span>'
|
||||
);
|
||||
|
||||
$this->purifier = new HTMLPurifier(array('HTML.EnableAttrID' => true));
|
||||
$this->assertPurification('<span id="moon">foobar</span>');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user