Skip to content

Commit

Permalink
zero as int not float (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Nov 2, 2023
1 parent 4be3c29 commit a46427c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/number_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ impl IntParse {
index += 1;
};
let mut value = match data.get(index) {
Some(b'0') => return Ok((Self::Float, index)),
Some(b'0') => {
index += 1;
return match data.get(index) {
Some(b'.') => Ok((Self::Float, index)),
Some(b'e') | Some(b'E') => Ok((Self::Float, index)),
Some(digit) if digit.is_ascii_digit() => json_err!(InvalidNumber, index),
_ => Ok((Self::Int(positive, NumberInt::Int(0)), index)),
};
}
Some(digit) if (b'1'..=b'9').contains(digit) => (digit & 0x0f) as i64,
Some(_) => return json_err!(InvalidNumber, index),
None => return json_err!(EofWhileParsingValue, index),
Expand Down
2 changes: 2 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ macro_rules! single_tests {
single_tests! {
string: ok => r#""foobar""#, "String(1..7) @ 1:1";
int_pos: ok => "1234", "Int(1234) @ 1:1";
int_zero: ok => "0", "Int(0) @ 1:1";
int_zero_space: ok => "0 ", "Int(0) @ 1:1";
int_neg: ok => "-1234", "Int(-1234) @ 1:1";
big_int: ok => "92233720368547758070", "BigInt(92233720368547758070) @ 1:1";
big_int_neg: ok => "-92233720368547758070", "BigInt(-92233720368547758070) @ 1:1";
Expand Down

0 comments on commit a46427c

Please sign in to comment.