4 * Validates an integer representation of pixels according to the HTML spec.
6 class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
17 public function __construct($max = null)
23 * @param string $string
24 * @param HTMLPurifier_Config $config
25 * @param HTMLPurifier_Context $context
28 public function validate($string, $config, $context)
30 $string = trim($string);
31 if ($string === '0') {
37 $length = strlen($string);
38 if (substr($string, $length - 2) == 'px') {
39 $string = substr($string, 0, $length - 2);
41 if (!is_numeric($string)) {
50 // upper-bound value, extremely high values can
51 // crash operating systems, see <http://ha.ckers.org/imagecrash.html>
52 // WARNING, above link WILL crash you if you're using Windows
54 if ($this->max !== null && $int > $this->max) {
55 return (string)$this->max;
61 * @param string $string
62 * @return HTMLPurifier_AttrDef
64 public function make($string)
71 $class = get_class($this);
72 return new $class($max);