Ident.php 517 B

123456789101112131415161718192021222324
  1. <?php
  2. /**
  3. * Validates based on {ident} CSS grammar production
  4. */
  5. class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef
  6. {
  7. public function validate($string, $config, $context) {
  8. $string = trim($string);
  9. // early abort: '' and '0' (strings that convert to false) are invalid
  10. if (!$string) return false;
  11. $pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/';
  12. if (!preg_match($pattern, $string)) return false;
  13. return $string;
  14. }
  15. }
  16. // vim: et sw=4 sts=4