From fa2e86a558c0cec284fe5de58c42104fd7ad20dc Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Fri, 24 Mar 2017 21:50:09 +0100 Subject: [PATCH] fix for #94 (#95) parse_utf8_char() makes the assumption that at least four bytes or one UTF-8 glyph are still to read in the input. --- src/event.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/event.rs b/src/event.rs index 45c0438..4c70ea9 100644 --- a/src/event.rs +++ b/src/event.rs @@ -315,12 +315,17 @@ fn parse_utf8_char(c: u8, iter: &mut I) -> Result bytes.push(c); loop { - bytes.push(iter.next().unwrap().unwrap()); - if let Ok(st) = str::from_utf8(bytes) { - return Ok(st.chars().next().unwrap()); - } - if bytes.len() >= 4 { - return error; + match iter.next() { + Some(Ok(next)) => { + bytes.push(next); + if let Ok(st) = str::from_utf8(bytes) { + return Ok(st.chars().next().unwrap()); + } + if bytes.len() >= 4 { + return error; + } + } + _ => return error, } } }