mirror of
https://github.com/nushell/nushell.git
synced 2025-03-26 15:26:51 +01: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
@ -207,18 +207,19 @@ impl<Iter: Iterator<Item = u8>> ParseNumber<Iter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_float {
|
if !is_float {
|
||||||
Ok(Number::F64(
|
if res.starts_with('-') {
|
||||||
res.parse::<f64>().expect("Internal error: json parsing"),
|
if let Ok(n) = res.parse::<i64>() {
|
||||||
))
|
return Ok(Number::I64(n));
|
||||||
} else if res.starts_with('-') {
|
}
|
||||||
Ok(Number::I64(
|
} else if let Ok(n) = res.parse::<u64>() {
|
||||||
res.parse::<i64>().expect("Internal error: json parsing"),
|
return Ok(Number::U64(n));
|
||||||
))
|
}
|
||||||
} else {
|
}
|
||||||
Ok(Number::U64(
|
|
||||||
res.parse::<u64>().expect("Internal error: json parsing"),
|
match res.parse::<f64>() {
|
||||||
))
|
Ok(n) => Ok(Number::F64(n)),
|
||||||
|
_ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),
|
_ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),
|
||||||
|
Loading…
Reference in New Issue
Block a user