From fc664ea0220d244f8400d6c4572c0fc3ea4b253a Mon Sep 17 00:00:00 2001 From: Pat Sier Date: Thu, 16 Feb 2023 20:29:36 -0600 Subject: [PATCH] fix: handle invalid utf-8 with lossy conversion (#45) --- src/reader.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 659cd86..07c2600 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -998,7 +998,7 @@ where ) -> Result { let mut element = Element::default(); let tag = start.local_name(); - element.name = str::from_utf8(tag).unwrap().to_string(); + element.name = String::from_utf8_lossy(tag).to_string(); element.attrs = attrs; loop { let mut e = self.reader.read_event(&mut self.buf)?; @@ -1114,8 +1114,8 @@ where .filter_map(Result::ok) .map(|a| { ( - str::from_utf8(a.key).unwrap().to_string(), - str::from_utf8(&a.value).unwrap().to_string(), + String::from_utf8_lossy(a.key).to_string(), + String::from_utf8_lossy(&a.value).to_string(), ) }) .collect()