From 7af68b1a7368b701d223debd5b07b0ce07e11d8e Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 11 Sep 2024 10:16:31 +0100 Subject: [PATCH] Prevent SVG parse errors from causing a panic --- packages/dom/src/util.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/dom/src/util.rs b/packages/dom/src/util.rs index 0101074c..b4448c33 100644 --- a/packages/dom/src/util.rs +++ b/packages/dom/src/util.rs @@ -113,7 +113,10 @@ impl RequestHandler for ImageHandler { ..Default::default() }; - let tree = Tree::from_data(&bytes, &options).unwrap(); + const DUMMY_SVG : &[u8] = r#""#.as_bytes(); + + let tree = Tree::from_data(&bytes, &options) + .unwrap_or_else(|_| Tree::from_data(DUMMY_SVG, &options).unwrap()); callback.call(Resource::Svg(self.0, Box::new(tree))); } }