Ticket Details

default format is not being passed to validation function correctly

BUG Ticket (closed)

###What happened:
- In writing a custom validation function, I found that 'format' kept on returning '0'.  However, I was able to find the format "any" specified by $options['format'].

###What was expected:
- When there is no format specified, it would say "any" or "all" as it says in the documentation 


### My code samples 
#### my custom validation: 
     
    Validator::add('sampleValid', function(&$value, $format = null, array $options = array()) { 
        var_dump("format = ", $format, $options['format']); 
        exit(); 
    }

####  my call : 
    $validations = array( 
        'inputName' => array( 
            array('sampleValid', 'message'=> 'this does not work the sample valid')
        )
    );
    return $document->save($this->request->data, array('validate' => $validations)); 



#### results (new lined for readability) 
string(9) "format = "   

int(0)   

string(3) "any"


### My Thoughts 
going into the code i found that the format is actually being set to 0 in \lithium\util\Validator lines 606-609 if $format is just "any" and rules = array('any') which seems to happen when you do not specify a format

    606 if (in_array($format, array(null, 'all', 'any'))) {
    607     $formats = array_keys($rules);
    608     $options['all'] = ($format == 'all');
    609 }

    

on 05.26.11 reported by: smergler owned by: Howard

Updates

(fixed) on 06.03.11 by Howard
  • owner was changed to Howard
  • status was changed to closed
  • resolution was changed to fixed
Fixed in [860cffbd3d455d64dc7e31f150887a9122a5af3d] Thanks for the report!