From 32f643f98686c79f373a1c6830be7666bb810dc0 Mon Sep 17 00:00:00 2001 From: Roma Sokolov Date: Fri, 5 Feb 2016 10:26:59 +0000 Subject: [PATCH] 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) --- json/src/de.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/json/src/de.rs b/json/src/de.rs index 86631bf..9f526e4 100644 --- a/json/src/de.rs +++ b/json/src/de.rs @@ -861,16 +861,16 @@ impl Iterator for JSONStream // 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)) } } }