Skip to content

Commit ba0b795

Browse files
committed
numericRangeCheck logic tree fix for default no errors
discovered bug when inputs within range, default return value "OK" not getting returned to caller due to else branch removed else branch & curly braces. explained: input val = 1, allowedrange=min1 logic tree entry will be at line 1034 indexOf min but value will not be less than minval, so error return is skipped, but the else branch on line 1039 will not be entered, so it is also skipped, and nothing is returned to the caller. since nothing is returned first, program flow will continue into new line 1039 and func will return array with single element val="ok" here is expanded function for testing by paste replace into script and look at console.log for debugging: /** * Test numeric against allowed range * * @param $value int * @param $rangeAllowed str; (1-2, min1, max2) * @return array */ numericRangeCheck : function($value, $rangeAllowed) { console.log('numericRangeCheck inputs: value "'+$value+'", rangeAllowed "' +$rangeAllowed+'"' ); // split by dash var range = $.split($rangeAllowed, '-'); console.log('range='+range); // range ? if (range.length == 2 && ($value < parseInt(range[0],10) || $value > parseInt(range[1],10) )) { // value is out of range console.log('value "'+$value+'", outside of range "' +$rangeAllowed+'"' ); return [ "out", range[0], range[1] ] ; } else if ($rangeAllowed.indexOf('min') === 0) // min { console.log('range min'); // check if above min var minQty = parseInt($rangeAllowed.substr(3),10); console.log(minQty); if($value < minQty) { console.log('value "'+$value+'", less than min "' +minQty+'"' ); return [ "min", minQty ] ; } } else if ($rangeAllowed.indexOf('max') === 0) // max { console.log('range max'); var maxQty = parseInt($rangeAllowed.substr(3),10); if($value > maxQty) { console.log('value "'+$value+'", more than max "' +maxQty+'"' ); return [ "max", maxQty ] ; } } // value is in allowed range console.log('value "'+$value+'", within range "' +$rangeAllowed+'"' ); return [ "ok" ]; },
1 parent 731a0c8 commit ba0b795

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

form-validator/jquery.form-validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@
10351035
{ return ["min", minmax]; } // value is below min
10361036
else if (rangeAllowed.indexOf('max') === 0 && (value > minmax ) ) // max
10371037
{ return ["max", minmax]; } // value is above max
1038-
else { return [ "ok" ] ; } // value is in allowed range
1038+
// since no other returns executed, value is in allowed range
1039+
return [ "ok" ] ;
10391040
},
10401041

10411042

0 commit comments

Comments
 (0)