mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 00:41:52 +00:00
Commit dud AttrDef integer.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@235 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
eca0f68c1f
commit
71c4a3c50c
37
library/HTMLPurifier/AttrDef/Integer.php
Normal file
37
library/HTMLPurifier/AttrDef/Integer.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef.php';
|
||||||
|
|
||||||
|
// appears to be a dud class: no currently allowed CSS uses this type
|
||||||
|
// Uses this: widows, orphans, z-index, counter-increment, counter-reset
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef
|
||||||
|
{
|
||||||
|
|
||||||
|
var $non_negative = false;
|
||||||
|
|
||||||
|
function HTMLPurifier_AttrDef_Integer($non_negative = false) {
|
||||||
|
$this->non_negative = $non_negative;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validate($integer, $config, &$context) {
|
||||||
|
|
||||||
|
$integer = $this->parseCDATA($integer);
|
||||||
|
if ($integer === '') return false;
|
||||||
|
|
||||||
|
if ( !$this->non_negative && $integer[0] === '-' ) {
|
||||||
|
$digits = substr($integer, 1);
|
||||||
|
} elseif( $integer[0] === '+' ) {
|
||||||
|
$digits = $integer = substr($integer, 1);
|
||||||
|
} else {
|
||||||
|
$digits = $integer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ctype_digit($digits)) return false;
|
||||||
|
return $integer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
38
tests/HTMLPurifier/AttrDef/IntegerTest.php
Normal file
38
tests/HTMLPurifier/AttrDef/IntegerTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrDef/Integer.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
$this->def = new HTMLPurifier_AttrDef_Integer();
|
||||||
|
|
||||||
|
$this->assertDef('0');
|
||||||
|
$this->assertDef('1');
|
||||||
|
$this->assertDef('-1');
|
||||||
|
$this->assertDef('-10');
|
||||||
|
$this->assertDef('14');
|
||||||
|
$this->assertDef('+24', '24');
|
||||||
|
$this->assertDef(' 14 ', '14');
|
||||||
|
|
||||||
|
$this->assertDef('-1.4', false);
|
||||||
|
$this->assertDef('3.4', false);
|
||||||
|
$this->assertDef('asdf', false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNonNegative() {
|
||||||
|
|
||||||
|
$this->def = new HTMLPurifier_AttrDef_Integer(true);
|
||||||
|
|
||||||
|
$this->assertDef('0');
|
||||||
|
$this->assertDef('1');
|
||||||
|
$this->assertDef('-1', false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -66,6 +66,7 @@ $test_files[] = 'AttrDef/URITest.php';
|
|||||||
$test_files[] = 'AttrDef/CSSTest.php';
|
$test_files[] = 'AttrDef/CSSTest.php';
|
||||||
$test_files[] = 'AttrDef/CompositeTest.php';
|
$test_files[] = 'AttrDef/CompositeTest.php';
|
||||||
$test_files[] = 'AttrDef/ColorTest.php';
|
$test_files[] = 'AttrDef/ColorTest.php';
|
||||||
|
$test_files[] = 'AttrDef/IntegerTest.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