Changeset 3349

Show
Ignore:
Timestamp:
08/17/2008 10:28:18 AM (4 months ago)
Author:
Geert
Message:

Follow-up to r3340. Passing regular expressions as an argument of chars[] remains hacky business but should work more solidly now.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Validation.php

    r3340 r3349  
    271271                                        // Split the rule into the function and args 
    272272                                        $rule = $matches[1]; 
    273                                         $args = preg_split('/(?<!\\\\),\s*/', $matches[2]); 
    274  
    275                                         // Replace escaped comma with comma 
    276                                         $args = str_replace('\,', ',', $args); 
     273                                        $args = $matches[2]; 
     274 
     275                                        // Split the args, but don't touch them in case of a chars regex check 
     276                                        if ($rule !== 'chars') 
     277                                        { 
     278                                                $args = preg_split('/(?<!\\\\),\s*/', $args); 
     279                                                $args = str_replace('\\,', ',', $args); 
     280                                        } 
    277281                                } 
    278282 
     
    763767         * 
    764768         * @param   string  field value 
    765          * @param   array   allowed characters 
     769         * @param   string  allowed characters 
    766770         * @return  bool 
    767771         */ 
    768         public function chars($value, array $chars) 
    769         { 
    770                 return ! preg_match('![^'.implode('', $chars).']!', $value); 
     772        public function chars($value, $chars) 
     773        { 
     774                // Escape the preg_match delimeter 
     775                $chars = str_replace('~', '\\~', $chars); 
     776 
     777                // Prevent chars to escape the closing bracket of the character class 
     778                $chars = rtrim($chars, '\\'); 
     779 
     780                // Return FALSE if any char outside of chars list is found 
     781                return ! preg_match('~[^'.$chars.']~u', $value); 
    771782        } 
    772783