sahvx655-wq opened a new pull request, #418:
URL: https://github.com/apache/commons-validator/pull/418

   Following up on the request to look at other BigInteger/BigDecimal to 
integer conversions: BigIntegerValidator.validate("15E-1") returns 1 and 
validate("5E-1") returns 0. The integer-only format sets parseIntegerOnly, but 
that flag only stops at the decimal separator, so a fractional value written 
with a negative exponent and no decimal point is consumed in full. Since 
getFormat enables setParseBigDecimal, it reaches processParsedValue as a 
fractional BigDecimal (1.5, 0.5) and toBigInteger silently floors it towards 
zero. ByteValidator, IntegerValidator and LongValidator all return null for the 
same input because their parse yields a non-Long they reject, so BigInteger was 
the odd one out and quietly returned a different value than supplied.
   
   Reject a parsed value that carries a fractional part rather than truncating 
it, keeping the check in processParsedValue where the conversion happens. Whole 
numbers, exponent forms such as 1E2, integers beyond the long range and the 
lenient non-strict truncation of trailing fraction digits (1,234.5 to 1234, 
where parseIntegerOnly does stop at the dot) are unchanged. Added a regression 
test that fails before and passes after.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to