Skip to content

Commit 9d94e92

Browse files
committed
Require at least one digit after decimal point
1 parent c27b023 commit 9d94e92

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/de.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,30 +451,33 @@ impl<'de, R: Read<'de>> Deserializer<R> {
451451
&mut self,
452452
positive: bool,
453453
mut significand: u64,
454-
mut exponent: i32,
454+
exponent_before_decimal_point: i32,
455455
) -> Result<f64> {
456456
self.eat_char();
457457

458+
let mut exponent_after_decimal_point = 0;
458459
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
459460
let digit = (c - b'0') as u64;
460461

461462
if overflow!(significand * 10 + digit, u64::max_value()) {
463+
let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
462464
return self.parse_decimal_overflow(positive, significand, exponent);
463465
}
464466

465467
self.eat_char();
466468
significand = significand * 10 + digit;
467-
exponent -= 1;
469+
exponent_after_decimal_point -= 1;
468470
}
469471

470472
// Error if there is not at least one digit after the decimal point.
471-
if exponent == 0 {
473+
if exponent_after_decimal_point == 0 {
472474
match tri!(self.peek()) {
473475
Some(_) => return Err(self.peek_error(ErrorCode::InvalidNumber)),
474476
None => return Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
475477
}
476478
}
477479

480+
let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
478481
match tri!(self.peek_or_null()) {
479482
b'e' | b'E' => self.parse_exponent(positive, significand, exponent),
480483
_ => self.f64_from_parts(positive, significand, exponent),

0 commit comments

Comments
 (0)