mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 15:48:42 +00:00
64b5581bf2
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1751 48356398-32a2-884e-a903-53898d9a118a
38 lines
961 B
PHP
38 lines
961 B
PHP
<?php
|
|
|
|
/**
|
|
* Represents a Length as defined by CSS.
|
|
*/
|
|
class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
|
|
{
|
|
|
|
protected $nonNegative;
|
|
|
|
/**
|
|
* @param $non_negative Bool indication whether or not negative values are
|
|
* allowed.
|
|
*/
|
|
public function __construct($non_negative = false) {
|
|
$this->nonNegative = $non_negative;
|
|
}
|
|
|
|
public function validate($string, $config, $context) {
|
|
$string = $this->parseCDATA($string);
|
|
|
|
// Optimizations
|
|
if ($string === '') return false;
|
|
if ($string === '0') return '0';
|
|
if (strlen($string) === 1) return false;
|
|
|
|
$length = HTMLPurifier_Length::make($string);
|
|
if (!$length->isValid($this->nonNegative)) return false;
|
|
|
|
$n = $length->getN();
|
|
if ($this->nonNegative && $n < 0) return false;
|
|
|
|
return $length->toString();
|
|
}
|
|
|
|
}
|
|
|