Skip to content

Commit

Permalink
Prevent SVG parse errors from causing a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Sep 17, 2024
1 parent b53fb5d commit 7af68b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/dom/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ impl RequestHandler for ImageHandler {
..Default::default()
};

let tree = Tree::from_data(&bytes, &options).unwrap();
const DUMMY_SVG : &[u8] = r#"<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>"#.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)));
}
}
Expand Down

0 comments on commit 7af68b1

Please sign in to comment.