Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make arbitrary_precision preserve the exact string representation #786

Merged
merged 1 commit into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/de.rs
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
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