From 426fbd1f973788b16e576d974cd9bce29799aa6e Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 29 May 2007 16:51:32 +0000 Subject: [PATCH] [1.7.0] Complete Legacy element and attribute native support. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1115 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + TODO | 7 ++- library/HTMLPurifier/AttrDef/Enum.php | 11 +++- library/HTMLPurifier/HTMLModule.php | 10 ++-- library/HTMLPurifier/HTMLModule/Legacy.php | 60 +++++++++++++++++++--- smoketests/basic/legacy.css | 41 ++++++++++++++- smoketests/basic/legacy.html | 59 ++++++++++++++------- tests/HTMLPurifier/AttrDef/EnumTest.php | 5 ++ 8 files changed, 159 insertions(+), 35 deletions(-) diff --git a/NEWS b/NEWS index f254a927..df7895e4 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Configuration directives that accept hashes now allow new string format: key1:value1,key2:value2 ! ConfigDoc now factored into OOP design +! All deprecated elements now natively supported - Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work! . Unit test for ElementDef created, ElementDef behavior modified to be more flexible diff --git a/TODO b/TODO index e9fb016a..c56f6637 100644 --- a/TODO +++ b/TODO @@ -15,10 +15,6 @@ TODO List - Get all AttrTypes into string form # Clean up HTMLDefinition caching, need easy cache invalidation, versioning of caches, etc. - # Implement all deprecated tags and attributes - # Create parsing/standards compliance smoketest - # Reorganize Unit Tests - - Refactor loop tests (esp. AttrDef_URI) - Parse TinyMCE-style whitelist into our %HTML.Allow* whitelists 1.8 release [Refactor, refactor!] @@ -86,6 +82,9 @@ Ongoing - WordPress (mostly written, needs beta-testing) - eFiction - more! (look for ones that use WYSIWYGs) + - Complete basic smoketests + - Reorganize Unit Tests + - Refactor loop tests (esp. AttrDef_URI) Unknown release (on a scratch-an-itch basis) ? Semi-lossy dumb alternate character encoding transfor diff --git a/library/HTMLPurifier/AttrDef/Enum.php b/library/HTMLPurifier/AttrDef/Enum.php index 870d5294..fce16b0a 100644 --- a/library/HTMLPurifier/AttrDef/Enum.php +++ b/library/HTMLPurifier/AttrDef/Enum.php @@ -47,11 +47,18 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef /** * @param $string In form of comma-delimited list of case-insensitive - * valid values. Example: "foo,bar,baz" + * valid values. Example: "foo,bar,baz". Prepend "s:" to make + * case sensitive */ function make($string) { + if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') { + $string = substr($string, 2); + $sensitive = true; + } else { + $sensitive = false; + } $values = explode(',', $string); - return new HTMLPurifier_AttrDef_Enum($values); + return new HTMLPurifier_AttrDef_Enum($values, $sensitive); } } diff --git a/library/HTMLPurifier/HTMLModule.php b/library/HTMLPurifier/HTMLModule.php index 54c61928..4560a184 100644 --- a/library/HTMLPurifier/HTMLModule.php +++ b/library/HTMLPurifier/HTMLModule.php @@ -139,9 +139,13 @@ class HTMLPurifier_HTMLModule * @return Reference to created element */ function &addBlankElement($element) { - $this->elements[] = $element; - $this->info[$element] = new HTMLPurifier_ElementDef(); - $this->info[$element]->standalone = false; + if (!isset($this->info[$element])) { + $this->elements[] = $element; + $this->info[$element] = new HTMLPurifier_ElementDef(); + $this->info[$element]->standalone = false; + } else { + trigger_error("Definition for $element already exists in module, cannot redefine"); + } return $this->info[$element]; } diff --git a/library/HTMLPurifier/HTMLModule/Legacy.php b/library/HTMLPurifier/HTMLModule/Legacy.php index e5ee2717..5ec1f66b 100644 --- a/library/HTMLPurifier/HTMLModule/Legacy.php +++ b/library/HTMLPurifier/HTMLModule/Legacy.php @@ -51,12 +51,6 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule // setup modifications to old elements - $li =& $this->addBlankElement('li'); - $li->attr['value'] = new HTMLPurifier_AttrDef_Integer(); - - $ol =& $this->addBlankElement('ol'); - $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer(); - $align = 'Enum#left,right,center,justify'; $address =& $this->addBlankElement('address'); @@ -86,7 +80,59 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule $h->attr['align'] = $align; } - // to be continued... + $hr =& $this->addBlankElement('hr'); + $hr->attr['align'] = $align; + $hr->attr['noshade'] = 'Bool#noshade'; + $hr->attr['size'] = 'Pixels'; + $hr->attr['width'] = 'Length'; + + $img =& $this->addBlankElement('img'); + $img->attr['align'] = 'Enum#top,middle,bottom,left,right'; + $img->attr['border'] = 'Pixels'; + $img->attr['hspace'] = 'Pixels'; + $img->attr['vspace'] = 'Pixels'; + + // figure out this integer business + + $li =& $this->addBlankElement('li'); + $li->attr['value'] = new HTMLPurifier_AttrDef_Integer(); + $li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle'; + + $ol =& $this->addBlankElement('ol'); + $ol->attr['compact'] = 'Bool#compact'; + $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer(); + $ol->attr['type'] = 'Enum#s:1,i,I,a,A'; + + $p =& $this->addBlankElement('p'); + $p->attr['align'] = $align; + + $pre =& $this->addBlankElement('pre'); + $pre->attr['width'] = 'Number'; + + // script omitted + + $table =& $this->addBlankElement('table'); + $table->attr['align'] = 'Enum#left,center,right'; + $table->attr['bgcolor'] = 'Color'; + + $tr =& $this->addBlankElement('tr'); + $tr->attr['bgcolor'] = 'Color'; + + $th =& $this->addBlankElement('th'); + $th->attr['bgcolor'] = 'Color'; + $th->attr['height'] = 'Length'; + $th->attr['nowrap'] = 'Bool#nowrap'; + $th->attr['width'] = 'Length'; + + $td =& $this->addBlankElement('td'); + $td->attr['bgcolor'] = 'Color'; + $td->attr['height'] = 'Length'; + $td->attr['nowrap'] = 'Bool#nowrap'; + $td->attr['width'] = 'Length'; + + $ul =& $this->addBlankElement('ul'); + $ul->attr['compact'] = 'Bool#compact'; + $ul->attr['type'] = 'Enum#square,disc,circle'; } diff --git a/smoketests/basic/legacy.css b/smoketests/basic/legacy.css index 34fbeff7..d6d673ac 100644 --- a/smoketests/basic/legacy.css +++ b/smoketests/basic/legacy.css @@ -23,10 +23,49 @@ hr[noshade='noshade'], hr[width='50'], hr[size='50'], +img[align='right'], +img[border='3'], +img[hspace='5'], +img[vspace='5'], + +input[align='right'], +legend[align='center'], + +li[type='A'], +li[value='5'], + +ol[compact='compact'], +ol[start='3'], +ol[type='I'], + +p[align='right'], + +pre[width='50'], + +table[align='right'], +table[bgcolor='#0000FF'], + +tr[bgcolor='#0000FF'], + +td[bgcolor='#0000FF'], +td[height='50'], +td[nowrap='nowrap'], +td[width='200'], + +th[bgcolor='#0000FF'], +th[height='50'], +th[nowrap='nowrap'], +th[width='200'], + +ul[compact='compact'], +ul[type='square'], + .insert-declarations-above {background:#008000; color:#FFF; font-weight:bold;} font {background:#BFB;} u {border:1px solid #000;} hr {height:1em;} -hr[size='50'] {height:50px;} \ No newline at end of file +hr[size='50'] {height:50px;} +img[border='3'] {border: 3px solid #000;} +li[type='a'], li[value='5'] {color:#DDD;} diff --git a/smoketests/basic/legacy.html b/smoketests/basic/legacy.html index a34aabeb..00919734 100644 --- a/smoketests/basic/legacy.html +++ b/smoketests/basic/legacy.html @@ -76,26 +76,49 @@ hr@width hr@size
+img@align | +img@border | +img@hspace | +img@vspace + + + +Legend + +
    +
  1. li@type (ensure that it's a capital A)
  2. +
  3. li@value
  4. +
+ +
  1. ol@compact
+
  1. ol@start
+
  1. ol@type
+ +

p@align

+ +
pre@width
+ + + +
table@align
+
table@bgcolor
+ +
tr@bgcolor
+ +
td@bgcolor
+
td@height
+
td@nowrap
+
td@width
+ +
th@bgcolor
+
th@height
+
th@nowrap
+
th@width
+ + + - - \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/EnumTest.php b/tests/HTMLPurifier/AttrDef/EnumTest.php index 79669be3..fe405d85 100644 --- a/tests/HTMLPurifier/AttrDef/EnumTest.php +++ b/tests/HTMLPurifier/AttrDef/EnumTest.php @@ -25,9 +25,14 @@ class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness function test_make() { $factory = new HTMLPurifier_AttrDef_Enum(); + $def = $factory->make('foo,bar'); $def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'bar')); $this->assertIdentical($def, $def2); + + $def = $factory->make('s:foo,BAR'); + $def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'BAR'), true); + $this->assertIdentical($def, $def2); } }