diff --git a/library/HTMLPurifier/AttrDef.php b/library/HTMLPurifier/AttrDef.php
index cdd90a60..ad7ab384 100644
--- a/library/HTMLPurifier/AttrDef.php
+++ b/library/HTMLPurifier/AttrDef.php
@@ -1,10 +1,12 @@
def = $def;
+ function HTMLPurifier_AttrDef() {}
+
+ function validate() {
+ trigger_error('Cannot call abstract function', E_USER_ERROR);
}
}
diff --git a/library/HTMLPurifier/AttrDef/Enum.php b/library/HTMLPurifier/AttrDef/Enum.php
new file mode 100644
index 00000000..7cb7ec4c
--- /dev/null
+++ b/library/HTMLPurifier/AttrDef/Enum.php
@@ -0,0 +1,25 @@
+valid_values = array_flip($valid_values);
+ $this->case_sensitive = $case_sensitive;
+ }
+
+ function validate($string) {
+ if (!$this->case_sensitive) {
+ $string = ctype_lower($string) ? $string : strtolower($string);
+ }
+ return isset($this->valid_values[$string]);
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/library/HTMLPurifier/Definition.php b/library/HTMLPurifier/Definition.php
index a0e61e2f..8dca40ee 100644
--- a/library/HTMLPurifier/Definition.php
+++ b/library/HTMLPurifier/Definition.php
@@ -92,72 +92,66 @@ class HTMLPurifier_Definition
$e_form_content = new HTMLPurifier_ChildDef_Optional(''); //unused
$e_form_button_content = new HTMLPurifier_ChildDef_Optional(''); // unused
- $this->info['ins'] =
- $this->info['del'] =
- $this->info['blockquote'] =
- $this->info['dd'] =
- $this->info['li'] =
- $this->info['div'] = new HTMLPurifier_ElementDef($e_Flow);
+ $this->info['child'] = array();
- $this->info['em'] =
- $this->info['strong'] =
- $this->info['dfn'] =
- $this->info['code'] =
- $this->info['samp'] =
- $this->info['kbd'] =
- $this->info['var'] =
- $this->info['code'] =
- $this->info['samp'] =
- $this->info['kbd'] =
- $this->info['var'] =
- $this->info['cite'] =
- $this->info['abbr'] =
- $this->info['acronym'] =
- $this->info['q'] =
- $this->info['sub'] =
- $this->info['tt'] =
- $this->info['sup'] =
- $this->info['i'] =
- $this->info['b'] =
- $this->info['big'] =
- $this->info['small'] =
- $this->info['u'] =
- $this->info['s'] =
- $this->info['strike'] =
- $this->info['bdo'] =
- $this->info['span'] =
- $this->info['dt'] =
- $this->info['p'] =
- $this->info['h1'] =
- $this->info['h2'] =
- $this->info['h3'] =
- $this->info['h4'] =
- $this->info['h5'] =
- $this->info['h6'] = new HTMLPurifier_ElementDef($e_Inline);
+ $this->info['child']['ins'] =
+ $this->info['child']['del'] =
+ $this->info['child']['blockquote'] =
+ $this->info['child']['dd'] =
+ $this->info['child']['li'] =
+ $this->info['child']['div'] = $e_Flow;
- $this->info['ol'] =
- $this->info['ul'] =
- new HTMLPurifier_ElementDef(
- new HTMLPurifier_ChildDef_Required('li')
- );
+ $this->info['child']['em'] =
+ $this->info['child']['strong'] =
+ $this->info['child']['dfn'] =
+ $this->info['child']['code'] =
+ $this->info['child']['samp'] =
+ $this->info['child']['kbd'] =
+ $this->info['child']['var'] =
+ $this->info['child']['code'] =
+ $this->info['child']['samp'] =
+ $this->info['child']['kbd'] =
+ $this->info['child']['var'] =
+ $this->info['child']['cite'] =
+ $this->info['child']['abbr'] =
+ $this->info['child']['acronym'] =
+ $this->info['child']['q'] =
+ $this->info['child']['sub'] =
+ $this->info['child']['tt'] =
+ $this->info['child']['sup'] =
+ $this->info['child']['i'] =
+ $this->info['child']['b'] =
+ $this->info['child']['big'] =
+ $this->info['child']['small'] =
+ $this->info['child']['u'] =
+ $this->info['child']['s'] =
+ $this->info['child']['strike'] =
+ $this->info['child']['bdo'] =
+ $this->info['child']['span'] =
+ $this->info['child']['dt'] =
+ $this->info['child']['p'] =
+ $this->info['child']['h1'] =
+ $this->info['child']['h2'] =
+ $this->info['child']['h3'] =
+ $this->info['child']['h4'] =
+ $this->info['child']['h5'] =
+ $this->info['child']['h6'] = $e_Inline;
- $this->info['dl'] =
- new HTMLPurifier_ElementDef(
- new HTMLPurifier_ChildDef_Required('dt|dd')
- );
- $this->info['address'] =
- new HTMLPurifier_ElementDef(
- new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline".
- " | $e_misc_inline")
- );
+ $this->info['child']['ol'] =
+ $this->info['child']['ul'] = new HTMLPurifier_ChildDef_Required('li');
- $this->info['img'] =
- $this->info['br'] =
- $this->info['hr'] = new HTMLPurifier_ElementDef(new HTMLPurifier_ChildDef_Empty());
+ $this->info['child']['dl'] = new HTMLPurifier_ChildDef_Required('dt|dd');
+ $this->info['child']['address'] =
+ new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline".
+ " | $e_misc_inline");
- $this->info['pre'] = new HTMLPurifier_ElementDef($e_pre_content);
+ $this->info['child']['img'] =
+ $this->info['child']['br'] =
+ $this->info['child']['hr'] = new HTMLPurifier_ChildDef_Empty();
- $this->info['a'] = new HTMLPurifier_ElementDef($e_a_content);
+ $this->info['child']['pre'] = $e_pre_content;
+
+ $this->info['child']['a'] = $e_a_content;
}
diff --git a/library/HTMLPurifier/Strategy/FixNesting.php b/library/HTMLPurifier/Strategy/FixNesting.php
index b0b2ca0e..ad54ed65 100644
--- a/library/HTMLPurifier/Strategy/FixNesting.php
+++ b/library/HTMLPurifier/Strategy/FixNesting.php
@@ -39,8 +39,8 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
// $j is index of end token
// have DTD child def validate children
- $element_def = $this->definition->info[$tokens[$i]->name];
- $result = $element_def->child_def->validateChildren($child_tokens);
+ $child_def = $this->definition->info['child'][$tokens[$i]->name];
+ $result = $child_def->validateChildren($child_tokens);
// process result
if ($result === true) {
diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php
index 3d0e9b67..4e58dd49 100644
--- a/library/HTMLPurifier/Strategy/MakeWellFormed.php
+++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php
@@ -23,10 +23,10 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
$result[] = $token;
continue;
}
- $info = $this->definition->info[$token->name]; // assumption but valid
+ $info = $this->definition->info['child'][$token->name]; // assumption but valid
// test if it claims to be a start tag but is empty
- if ($info->child_def->type == 'empty' &&
+ if ($info->type == 'empty' &&
$token->type == 'start' ) {
$result[] = new HTMLPurifier_Token_Empty($token->name,
@@ -35,7 +35,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
}
// test if it claims to be empty but really is a start tag
- if ($info->child_def->type != 'empty' &&
+ if ($info->type != 'empty' &&
$token->type == 'empty' ) {
$result[] = new HTMLPurifier_Token_Start($token->name,
diff --git a/library/HTMLPurifier/Strategy/RemoveForeignElements.php b/library/HTMLPurifier/Strategy/RemoveForeignElements.php
index 7418dfc6..e5755bb8 100644
--- a/library/HTMLPurifier/Strategy/RemoveForeignElements.php
+++ b/library/HTMLPurifier/Strategy/RemoveForeignElements.php
@@ -19,7 +19,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
$result = array();
foreach($tokens as $token) {
if (!empty( $token->is_tag )) {
- if (!isset($this->definition->info[$token->name])) {
+ if (!isset($this->definition->info['child'][$token->name])) {
// invalid tag, generate HTML and insert in
$token = new HTMLPurifier_Token_Text(
$this->generator->generateFromToken($token)
diff --git a/tests/HTMLPurifier/AttrDef/EnumTest.php b/tests/HTMLPurifier/AttrDef/EnumTest.php
new file mode 100644
index 00000000..8e8acbf7
--- /dev/null
+++ b/tests/HTMLPurifier/AttrDef/EnumTest.php
@@ -0,0 +1,28 @@
+assertTrue($def->validate('one'));
+ $this->assertTrue($def->validate('ONE'));
+
+ }
+
+ function testCaseSensitive() {
+
+ $def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'), true);
+
+ $this->assertTrue($def->validate('one'));
+ $this->assertFalse($def->validate('ONE'));
+
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/index.php b/tests/index.php
index 9267a600..5cb61927 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -32,6 +32,7 @@ $test->addTestFile('HTMLPurifier/Strategy/MakeWellFormedTest.php');
$test->addTestFile('HTMLPurifier/Strategy/FixNestingTest.php');
$test->addTestFile('HTMLPurifier/Strategy/CompositeTest.php');
$test->addTestFile('HTMLPurifier/Strategy/CoreTest.php');
+$test->addTestFile('HTMLPurifier/AttrDef/EnumTest.php');
$test->run( new HtmlReporter() );