Tighter CSS selector validation.
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / Ident.php
blob779794a0b3d2735c844d391680c61d1a68f84885
1 <?php
3 /**
4 * Validates based on {ident} CSS grammar production
5 */
6 class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef
9 public function validate($string, $config, $context) {
11 $string = trim($string);
13 // early abort: '' and '0' (strings that convert to false) are invalid
14 if (!$string) return false;
16 $pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/';
17 if (!preg_match($pattern, $string)) return false;
18 return $string;
24 // vim: et sw=4 sts=4