numericRangeCheck logic tree fix for default no errors #173
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ] ;
}
}