Skip to content

Commit

Permalink
Make arbitrary_precision preserve the exact string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifengx committed Jul 17, 2021
1 parent ea39063 commit 2152324
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
fn scan_number(&mut self, buf: &mut String) -> Result<()> {
match tri!(self.peek_or_null()) {
b'.' => self.scan_decimal(buf),
b'e' | b'E' => self.scan_exponent(buf),
c @ (b'e' | b'E') => self.scan_exponent(c as char, buf),
_ => Ok(()),
}
}
Expand All @@ -923,19 +923,20 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}

match tri!(self.peek_or_null()) {
b'e' | b'E' => self.scan_exponent(buf),
c @ (b'e' | b'E') => self.scan_exponent(c as char, buf),
_ => Ok(()),
}
}

#[cfg(feature = "arbitrary_precision")]
fn scan_exponent(&mut self, buf: &mut String) -> Result<()> {
fn scan_exponent(&mut self, e: char, buf: &mut String) -> Result<()> {
self.eat_char();
buf.push('e');
buf.push(e);

match tri!(self.peek_or_null()) {
b'+' => {
self.eat_char();
buf.push('+');
}
b'-' => {
self.eat_char();
Expand Down
6 changes: 6 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,14 @@ fn test_parse_number() {
#[cfg(feature = "arbitrary_precision")]
test_parse_ok(vec![
("1e999", Number::from_string_unchecked("1e999".to_owned())),
("1e+999", Number::from_string_unchecked("1e+999".to_owned())),
("-1e999", Number::from_string_unchecked("-1e999".to_owned())),
("1e-999", Number::from_string_unchecked("1e-999".to_owned())),
("1E999", Number::from_string_unchecked("1E999".to_owned())),
("1E+999", Number::from_string_unchecked("1E+999".to_owned())),
("-1E999", Number::from_string_unchecked("-1E999".to_owned())),
("1E-999", Number::from_string_unchecked("1E-999".to_owned())),
("1E+000", Number::from_string_unchecked("1E+000".to_owned())),
(
"2.3e999",
Number::from_string_unchecked("2.3e999".to_owned()),
Expand Down

0 comments on commit 2152324

Please sign in to comment.