mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 08:51:53 +00:00
Add NumberSpan definition (non-DTD, but applies to enough to be useful). All widely used non-deprecated attributes have been implemented (except for rel/rev, but that's tricky). Add note about quirky COL handling and possible implementation of a workaround.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@174 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
d429989f86
commit
d5e75f2616
3
TODO.txt
3
TODO.txt
@ -7,3 +7,6 @@ Primary:
|
|||||||
Code issues:
|
Code issues:
|
||||||
- Rename AbstractTest to Harness
|
- Rename AbstractTest to Harness
|
||||||
- (?) Create a TokenFactory to prevent really long lines
|
- (?) Create a TokenFactory to prevent really long lines
|
||||||
|
|
||||||
|
Enhancements:
|
||||||
|
- Do fixes for Firefox's inability to handle COL alignment props (Bug 915)
|
23
library/HTMLPurifier/AttrDef/NumberSpan.php
Normal file
23
library/HTMLPurifier/AttrDef/NumberSpan.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
|
||||||
|
// for col and row spans, essentially, a positive integer
|
||||||
|
class HTMLPurifier_AttrDef_NumberSpan extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
function validate($string) {
|
||||||
|
|
||||||
|
$string = trim($string);
|
||||||
|
if ($string === '') return false;
|
||||||
|
if ($string === '1') return false; // this is the default value
|
||||||
|
if (!is_numeric($string)) return false;
|
||||||
|
$int = (int) $string;
|
||||||
|
if ($int <= 0) return false;
|
||||||
|
return (string) $int;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -9,6 +9,7 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
require_once 'HTMLPurifier/AttrDef/Pixels.php';
|
require_once 'HTMLPurifier/AttrDef/Pixels.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/Length.php';
|
require_once 'HTMLPurifier/AttrDef/Length.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/MultiLength.php';
|
require_once 'HTMLPurifier/AttrDef/MultiLength.php';
|
||||||
|
require_once 'HTMLPurifier/AttrDef/NumberSpan.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform.php';
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||||
@ -290,17 +291,26 @@ class HTMLPurifier_Definition
|
|||||||
$this->info['table']->attr['border'] = new HTMLPurifier_AttrDef_Pixels();
|
$this->info['table']->attr['border'] = new HTMLPurifier_AttrDef_Pixels();
|
||||||
|
|
||||||
$e_Length = new HTMLPurifier_AttrDef_Length();
|
$e_Length = new HTMLPurifier_AttrDef_Length();
|
||||||
$this->info['table']->attr['cellpadding'] = $e_Length;
|
$this->info['table']->attr['cellpadding'] =
|
||||||
$this->info['table']->attr['cellspacing'] = $e_Length;
|
$this->info['table']->attr['cellspacing'] =
|
||||||
$this->info['table']->attr['width'] = $e_Length;
|
$this->info['table']->attr['width'] =
|
||||||
$this->setAttrForTableElements('charoff', $e_Length);
|
$this->info['img']->attr['height'] =
|
||||||
$this->info['img']->attr['height'] = $e_Length;
|
|
||||||
$this->info['img']->attr['width'] = $e_Length;
|
$this->info['img']->attr['width'] = $e_Length;
|
||||||
|
$this->setAttrForTableElements('charoff', $e_Length);
|
||||||
|
|
||||||
$e_MultiLength = new HTMLPurifier_AttrDef_MultiLength();
|
$e_MultiLength = new HTMLPurifier_AttrDef_MultiLength();
|
||||||
$this->info['col']->attr['width'] = $e_MultiLength;
|
$this->info['col']->attr['width'] =
|
||||||
$this->info['colgroup']->attr['width'] = $e_MultiLength;
|
$this->info['colgroup']->attr['width'] = $e_MultiLength;
|
||||||
|
|
||||||
|
$e__NumberSpan = new HTMLPurifier_AttrDef_NumberSpan();
|
||||||
|
$this->info['colgroup']->attr['span'] =
|
||||||
|
$this->info['col']->attr['span'] =
|
||||||
|
$this->info['td']->attr['rowspan'] =
|
||||||
|
$this->info['th']->attr['rowspan'] =
|
||||||
|
$this->info['td']->attr['colspan'] =
|
||||||
|
$this->info['th']->attr['colspan'] = $e__NumberSpan;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// UNIMP : info_tag_transform : transformations of tags
|
// UNIMP : info_tag_transform : transformations of tags
|
||||||
|
|
||||||
|
28
tests/HTMLPurifier/AttrDef/NumberSpanTest.php
Normal file
28
tests/HTMLPurifier/AttrDef/NumberSpanTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||||
|
require_once 'HTMLPurifier/AttrDef/NumberSpan.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrDef_NumberSpanTest extends HTMLPurifier_AttrDefHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
$this->def = new HTMLPurifier_AttrDef_NumberSpan();
|
||||||
|
|
||||||
|
// this one requires a little explanation. A colspan="1" shouldn't
|
||||||
|
// exist at all: it's just a dud, since the default value is already
|
||||||
|
// supplied
|
||||||
|
$this->assertDef('1', false);
|
||||||
|
|
||||||
|
$this->assertDef('4');
|
||||||
|
$this->assertDef('4.5', '4'); // round down (truncate)
|
||||||
|
$this->assertDef('0', false);
|
||||||
|
$this->assertDef('-4', false);
|
||||||
|
$this->assertDef('asdf', false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -80,6 +80,9 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
|||||||
<td abbr="carrot">Carrot Humungous</td>
|
<td abbr="carrot">Carrot Humungous</td>
|
||||||
<td>$500.23</td>
|
<td>$500.23</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">Taken off the market</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
HTML;
|
HTML;
|
||||||
$expect[13] = $inputs[13];
|
$expect[13] = $inputs[13];
|
||||||
|
@ -45,6 +45,7 @@ $test_files[] = 'AttrDef/TextTest.php';
|
|||||||
$test_files[] = 'AttrDef/LangTest.php';
|
$test_files[] = 'AttrDef/LangTest.php';
|
||||||
$test_files[] = 'AttrDef/PixelsTest.php';
|
$test_files[] = 'AttrDef/PixelsTest.php';
|
||||||
$test_files[] = 'AttrDef/LengthTest.php';
|
$test_files[] = 'AttrDef/LengthTest.php';
|
||||||
|
$test_files[] = 'AttrDef/NumberSpanTest.php';
|
||||||
$test_files[] = 'IDAccumulatorTest.php';
|
$test_files[] = 'IDAccumulatorTest.php';
|
||||||
$test_files[] = 'TagTransformTest.php';
|
$test_files[] = 'TagTransformTest.php';
|
||||||
$test_files[] = 'AttrTransform/LangTest.php';
|
$test_files[] = 'AttrTransform/LangTest.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user