mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Prevents panic when parsing JSON containing large number (#6096)
* prevents panic when parsing JSON containing large number * fmt * check for '-' sign first * fmt * clippy
This commit is contained in:
parent
a1a5a3646b
commit
8a0bd20e84
1 changed files with 13 additions and 12 deletions
|
@ -207,18 +207,19 @@ impl<Iter: Iterator<Item = u8>> ParseNumber<Iter> {
|
|||
}
|
||||
}
|
||||
|
||||
if is_float {
|
||||
Ok(Number::F64(
|
||||
res.parse::<f64>().expect("Internal error: json parsing"),
|
||||
))
|
||||
} else if res.starts_with('-') {
|
||||
Ok(Number::I64(
|
||||
res.parse::<i64>().expect("Internal error: json parsing"),
|
||||
))
|
||||
} else {
|
||||
Ok(Number::U64(
|
||||
res.parse::<u64>().expect("Internal error: json parsing"),
|
||||
))
|
||||
if !is_float {
|
||||
if res.starts_with('-') {
|
||||
if let Ok(n) = res.parse::<i64>() {
|
||||
return Ok(Number::I64(n));
|
||||
}
|
||||
} else if let Ok(n) = res.parse::<u64>() {
|
||||
return Ok(Number::U64(n));
|
||||
}
|
||||
}
|
||||
|
||||
match res.parse::<f64>() {
|
||||
Ok(n) => Ok(Number::F64(n)),
|
||||
_ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),
|
||||
}
|
||||
}
|
||||
_ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),
|
||||
|
|
Loading…
Reference in a new issue