Commit ba0b795
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
1 file changed
+2
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | | - | |
| 1038 | + | |
| 1039 | + | |
1039 | 1040 | | |
1040 | 1041 | | |
1041 | 1042 | | |
| |||
0 commit comments