Fixed #34014 -- Fixed DecimalValidator validating 0 in positive exponent scientific notation.

Thanks Shiplu Mokaddim for the report.
This commit is contained in:
Kamil Turek 2022-09-16 21:43:12 +02:00 committed by Mariusz Felisiak
parent c11336cd99
commit ae509f8f08
2 changed files with 5 additions and 2 deletions

View File

@ -486,8 +486,10 @@ class DecimalValidator:
self.messages["invalid"], code="invalid", params={"value": value} self.messages["invalid"], code="invalid", params={"value": value}
) )
if exponent >= 0: if exponent >= 0:
# A positive exponent adds that many trailing zeros. digits = len(digit_tuple)
digits = len(digit_tuple) + exponent if digit_tuple != (0,):
# A positive exponent adds that many trailing zeros.
digits += exponent
decimals = 0 decimals = 0
else: else:
# If the absolute value of the negative exponent is larger than the # If the absolute value of the negative exponent is larger than the

View File

@ -548,6 +548,7 @@ TEST_DATA = [
Decimal("70E-6"), Decimal("70E-6"),
ValidationError, ValidationError,
), ),
(DecimalValidator(max_digits=2, decimal_places=1), Decimal("0E+1"), None),
# 'Enter a number.' errors # 'Enter a number.' errors
*[ *[
( (