Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.8.6

Bug #19630 Validate::string returns true for "max_length"=>0 when it shouldn't.
Submitted: 2012-10-03 17:58 UTC
From: helen_griffiths Assigned:
Status: Open Package: Validate (version 0.8.5)
PHP Version: 5.4.6 OS: Linux Fedora 3.5.3-1.fc17.x86_64
Roadmaps: (Not assigned)    
Subscription  


 [2012-10-03 17:58 UTC] helen_griffiths (Helen Griffiths)
Description: ------------ Validate::string used with max_length=>0 in the options array ought to return false when a string is longer than 0 characters, but actually returns true. Test script: --------------- $tucaspn = "0001234567" ; $tsha1 = "8216f35ab34f4e3910fd384565636f57dd7f50a2" ; $tpepper = "kittens0ft" ; $tchars = VALIDATE_NUM ; $tmin = 0 ; $tmax = 0 ; function ucasPnCheckerF($ucaspn,$pepper,$sha1,$min,$max,$chars) { // returns true or false return (Validate::string($ucaspn, array("min_length"=>$min, "max_length"=>$max, "format"=>$chars)) && sha1PepperChecker($ucaspn, $pepper, $sha1)) ; } if (ucasPnCheckerF($tucaspn,$tpepper,$tsha1,$tmin,$tmax,$tchars)) { echo "This should have failed but didn't.<br />" ; } else echo "I'll eat my hat." ; function ucasPnCheckerT($ucaspn,$pepper,$sha1,$min,$max,$chars) { // returns true or false return ((0 < $max) && Validate::string($ucaspn, array("min_length"=>$min, "max_length"=>$max, "format"=>$chars)) && sha1PepperChecker($ucaspn, $pepper, $sha1)) ; } if (ucasPnCheckerT($tucaspn,$tpepper,$tsha1,$tmin,$tmax,$tchars)) { echo "This should have failed.<br />" ; } else echo "Workaround for bug." ; Expected result: ---------------- I'll eat my hat. Workaround for bug. Actual result: -------------- This should have failed but didn't. Workaround for bug.

Comments

 [2012-10-03 18:32 UTC] helen_griffiths (Helen Griffiths)
Missing from the test script is a function definition. Sorry... function sha1PepperChecker ($given_string, $pepper, $sha1) { if( !(empty($given_string)) AND !(empty($pepper)) AND !(empty($sha1)) AND is_string($given_string) AND is_string($pepper) AND is_string($sha1) ) { return (sha1PepperMaker($given_string, $pepper) == $sha1); } else { echo "<p style='color: red'>I need valid string input.</p>"; return false; } }