Skip to content

Commit c38fc65

Browse files
authored
Merge pull request #786 from ruifengx/master
Make arbitrary_precision preserve the exact string representation
2 parents c9193d4 + 2152324 commit c38fc65

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/de.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
899899
fn scan_number(&mut self, buf: &mut String) -> Result<()> {
900900
match tri!(self.peek_or_null()) {
901901
b'.' => self.scan_decimal(buf),
902-
b'e' | b'E' => self.scan_exponent(buf),
902+
c @ (b'e' | b'E') => self.scan_exponent(c as char, buf),
903903
_ => Ok(()),
904904
}
905905
}
@@ -924,19 +924,20 @@ impl<'de, R: Read<'de>> Deserializer<R> {
924924
}
925925

926926
match tri!(self.peek_or_null()) {
927-
b'e' | b'E' => self.scan_exponent(buf),
927+
c @ (b'e' | b'E') => self.scan_exponent(c as char, buf),
928928
_ => Ok(()),
929929
}
930930
}
931931

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

937937
match tri!(self.peek_or_null()) {
938938
b'+' => {
939939
self.eat_char();
940+
buf.push('+');
940941
}
941942
b'-' => {
942943
self.eat_char();

tests/test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,14 @@ fn test_parse_number() {
10071007
#[cfg(feature = "arbitrary_precision")]
10081008
test_parse_ok(vec![
10091009
("1e999", Number::from_string_unchecked("1e999".to_owned())),
1010+
("1e+999", Number::from_string_unchecked("1e+999".to_owned())),
10101011
("-1e999", Number::from_string_unchecked("-1e999".to_owned())),
10111012
("1e-999", Number::from_string_unchecked("1e-999".to_owned())),
1013+
("1E999", Number::from_string_unchecked("1E999".to_owned())),
1014+
("1E+999", Number::from_string_unchecked("1E+999".to_owned())),
1015+
("-1E999", Number::from_string_unchecked("-1E999".to_owned())),
1016+
("1E-999", Number::from_string_unchecked("1E-999".to_owned())),
1017+
("1E+000", Number::from_string_unchecked("1E+000".to_owned())),
10121018
(
10131019
"2.3e999",
10141020
Number::from_string_unchecked("2.3e999".to_owned()),

0 commit comments

Comments
 (0)