mirror of
https://github.com/serde-rs/json.git
synced 2026-02-15 04:10:35 +00:00
Fixed error handling
.eof() can return Err, so do not try to unwrap() it unconditionally. Also, check result of .parse_whitespaces(), and report, if there is any errors. (thanks, @nixpulvis)
This commit is contained in:
parent
34b3a1e9ce
commit
32f643f986
@ -861,16 +861,16 @@ impl <T, Iter> Iterator for JSONStream<T, Iter>
|
||||
// skip whitespaces, if any
|
||||
// this helps with trailing whitespaces, since whitespaces between
|
||||
// values are handled for us.
|
||||
let _:Result<()> = self.deser.parse_whitespace();
|
||||
// Since Deserializer.eof() always return Ok(_), it's safe to
|
||||
// call .ok() here
|
||||
if self.deser.eof().ok().unwrap() {
|
||||
None
|
||||
} else {
|
||||
match de::Deserialize::deserialize(&mut self.deser) {
|
||||
if let Err(e) = self.deser.parse_whitespace() {
|
||||
return Some(Err(e))
|
||||
};
|
||||
match self.deser.eof() {
|
||||
Ok(true) => None,
|
||||
Ok(false) => match de::Deserialize::deserialize(&mut self.deser) {
|
||||
Ok(v) => Some(Ok(v)),
|
||||
Err(e) => Some(Err(e))
|
||||
}
|
||||
},
|
||||
Err(e) => Some(Err(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user