File indexing completed on 2024-12-22 05:36:18
0001 <?php 0002 0003 /** 0004 * Validates based on {ident} CSS grammar production 0005 */ 0006 class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef 0007 { 0008 0009 /** 0010 * @param string $string 0011 * @param HTMLPurifier_Config $config 0012 * @param HTMLPurifier_Context $context 0013 * @return bool|string 0014 */ 0015 public function validate($string, $config, $context) 0016 { 0017 $string = trim($string); 0018 0019 // early abort: '' and '0' (strings that convert to false) are invalid 0020 if (!$string) { 0021 return false; 0022 } 0023 0024 $pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/'; 0025 if (!preg_match($pattern, $string)) { 0026 return false; 0027 } 0028 return $string; 0029 } 0030 } 0031 0032 // vim: et sw=4 sts=4