/** * Validates the number and unit. */ function validate() { // Special case: static $allowedUnits = array('em' => true, 'ex' => true, 'px' => true, 'in' => true, 'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true); if ($this->n === '+0' || $this->n === '-0') { $this->n = '0'; } if ($this->n === '0' && $this->unit === false) { return true; } if (!ctype_lower($this->unit)) { $this->unit = strtolower($this->unit); } if (!isset($allowedUnits[$this->unit])) { return false; } // Hack: $def = new HTMLPurifier_AttrDef_CSS_Number(); $a = false; // hack hack $result = $def->validate($this->n, $a, $a); if ($result === false) { return false; } $this->n = $result; return true; }
public function validate($number, $config, $context) { $result = parent::validate($number, $config, $context); if ($result === false) { return $result; } $float = (double) $result; if ($float < 0.0) { $result = '0'; } if ($float > 1.0) { $result = '1'; } return $result; }
/** * Validates the number and unit. */ protected function validate() { // Special case: if ($this->n === '+0' || $this->n === '-0') { $this->n = '0'; } if ($this->n === '0' && $this->unit === false) { return true; } if (!ctype_lower($this->unit)) { $this->unit = strtolower($this->unit); } if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) { return false; } // Hack: $def = new HTMLPurifier_AttrDef_CSS_Number(); $result = $def->validate($this->n, false, false); if ($result === false) { return false; } $this->n = $result; return true; }