0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-14 01:08:41 +00:00

[1.3.0] Implement user-unfriendly implementation of Strict doctype. We will try not to ship this one.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@556 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-11-22 18:17:39 +00:00
parent b0575cb888
commit b152448608
3 changed files with 48 additions and 11 deletions

View File

@ -12,7 +12,7 @@ BLOCKQUOTE changes from 'flow' to 'block'
U, S, STRIKE cut U, S, STRIKE cut
behavior: replace with appropriate inline span + CSS behavior: replace with appropriate inline span + CSS
ADDRESS from potpourri to Inline (removes p tags) ADDRESS from potpourri to Inline (removes p tags)
behavior: p tags silently dropped or replaced with something behavior: p tags silently dropped or replaced with something (<br>)
== Things we can loosen up == == Things we can loosen up ==

View File

@ -35,6 +35,11 @@ HTMLPurifier_ConfigSchema::define(
'versions.' 'versions.'
); );
HTMLPurifier_ConfigSchema::define(
'HTML', 'Strict', false, 'bool',
'Determines whether or not to use Transitional (loose) or Strict rulesets.'
);
/** /**
* Defines the purified HTML type with large amounts of objects. * Defines the purified HTML type with large amounts of objects.
* *
@ -111,13 +116,19 @@ class HTMLPurifier_HTMLDefinition
array( array(
'ins', 'del', 'blockquote', 'dd', 'li', 'div', 'em', 'strong', 'ins', 'del', 'blockquote', 'dd', 'li', 'div', 'em', 'strong',
'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym',
'q', 'sub', 'tt', 'sup', 'i', 'b', 'big', 'small', 'u', 's', 'q', 'sub', 'tt', 'sup', 'i', 'b', 'big', 'small',
'strike', 'bdo', 'span', 'dt', 'p', 'h1', 'h2', 'h3', 'h4', 'bdo', 'span', 'dt', 'p', 'h1', 'h2', 'h3', 'h4',
'h5', 'h6', 'ol', 'ul', 'dl', 'address', 'img', 'br', 'hr', 'h5', 'h6', 'ol', 'ul', 'dl', 'address', 'img', 'br', 'hr',
'pre', 'a', 'table', 'caption', 'thead', 'tfoot', 'tbody', 'pre', 'a', 'table', 'caption', 'thead', 'tfoot', 'tbody',
'colgroup', 'col', 'td', 'th', 'tr' 'colgroup', 'col', 'td', 'th', 'tr'
); );
if (!$config->get('HTML', 'Strict')) {
$allowed_tags[] = 'u';
$allowed_tags[] = 's';
$allowed_tags[] = 'strike';
}
foreach ($allowed_tags as $tag) { foreach ($allowed_tags as $tag) {
$this->info[$tag] = new HTMLPurifier_ElementDef(); $this->info[$tag] = new HTMLPurifier_ElementDef();
} }
@ -161,6 +172,7 @@ class HTMLPurifier_HTMLDefinition
$e_lists = 'ul | ol | dl'; $e_lists = 'ul | ol | dl';
$e_blocktext = 'pre | hr | blockquote | address'; $e_blocktext = 'pre | hr | blockquote | address';
$e_block = "p | $e_heading | div | $e_lists | $e_blocktext | table"; $e_block = "p | $e_heading | div | $e_lists | $e_blocktext | table";
$e_Block = new HTMLPurifier_ChildDef_Optional($e_block);
$e__flow = "#PCDATA | $e_block | $e_inline | $e_misc"; $e__flow = "#PCDATA | $e_block | $e_inline | $e_misc";
$e_Flow = new HTMLPurifier_ChildDef_Optional($e__flow); $e_Flow = new HTMLPurifier_ChildDef_Optional($e__flow);
$e_a_content = new HTMLPurifier_ChildDef_Optional("#PCDATA". $e_a_content = new HTMLPurifier_ChildDef_Optional("#PCDATA".
@ -176,11 +188,16 @@ class HTMLPurifier_HTMLDefinition
$this->info['del']->child = $this->info['del']->child =
new HTMLPurifier_ChildDef_Chameleon($e__inline, $e__flow); new HTMLPurifier_ChildDef_Chameleon($e__inline, $e__flow);
$this->info['blockquote']->child=
$this->info['dd']->child = $this->info['dd']->child =
$this->info['li']->child = $this->info['li']->child =
$this->info['div']->child = $e_Flow; $this->info['div']->child = $e_Flow;
if ($config->get('HTML', 'Strict')) {
$this->info['blockquote']->child = $e_Block;
} else {
$this->info['blockquote']->child = $e_Flow;
}
$this->info['caption']->child = $this->info['caption']->child =
$this->info['em']->child = $this->info['em']->child =
$this->info['strong']->child = $this->info['strong']->child =
@ -220,9 +237,13 @@ class HTMLPurifier_HTMLDefinition
$this->info['dl']->child = new HTMLPurifier_ChildDef_Required('dt|dd'); $this->info['dl']->child = new HTMLPurifier_ChildDef_Required('dt|dd');
$this->info['address']->child = if ($config->get('HTML', 'Strict')) {
new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline". $this->info['address']->child = $e_Inline
" | $e_misc_inline"); } else {
$this->info['address']->child =
new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline".
" | $e_misc_inline");
}
$this->info['img']->child = $this->info['img']->child =
$this->info['br']->child = $this->info['br']->child =
@ -254,7 +275,6 @@ class HTMLPurifier_HTMLDefinition
$this->info[$name]->type = 'inline'; $this->info[$name]->type = 'inline';
} }
$e_Block = new HTMLPurifier_ChildDef_Optional($e_block);
foreach ($e_Block->elements as $name => $bool) { foreach ($e_Block->elements as $name => $bool) {
$this->info[$name]->type = 'block'; $this->info[$name]->type = 'block';
} }

View File

@ -14,11 +14,28 @@ class HTMLPurifier_Test extends UnitTestCase
$this->assertIdentical($expect, $result); $this->assertIdentical($expect, $result);
} }
function test() { function testNull() {
$config = HTMLPurifier_Config::createDefault(); $this->purifier = new HTMLPurifier();
$this->purifier = new HTMLPurifier($config);
$this->assertPurification("Null byte\0", "Null byte"); $this->assertPurification("Null byte\0", "Null byte");
} }
function testStrict() {
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML', 'Strict', true);
$this->purifier = new HTMLPurifier($config);
$this->assertPurification(
'<u>Illegal underline</u>',
'Illegal underline'
);
$this->assertPurification(
'<blockquote>Illegal contents</blockquote>',
'<blockquote></blockquote>'
);
}
} }
?> ?>