From e93556a7ce24589ac34a53c54dc5c2bf2ea96942 Mon Sep 17 00:00:00 2001 From: MCorange Date: Fri, 17 Feb 2023 15:31:19 +0200 Subject: [PATCH] Fixed crash when file has no extension --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/renderer.rs | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17d6fbe..3e8f904 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,7 +596,7 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "svg2colored-png" -version = "1.0.2" +version = "1.0.3" dependencies = [ "clap", "color-eyre", diff --git a/Cargo.toml b/Cargo.toml index 7808610..7b300b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svg2colored-png" -version = "1.0.2" +version = "1.0.3" edition = "2021" description = "An SVG to PNG converter" authors = ["MCorange "] diff --git a/src/renderer.rs b/src/renderer.rs index 82097af..2353ea7 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -52,9 +52,13 @@ impl Renderer { } pub fn render(&self, path_in: PathBuf, out_dir: PathBuf) -> Result<(), ()> { - - if path_in.clone().extension().unwrap().to_str().unwrap() != "svg" { - return Err(util::logger::warning(format!("File '{}' is not of SVG type", path_in.to_str().unwrap()))); + let ext = path_in.clone(); + let ext = match ext.extension() { + Some(e) => e, + None => return Err(util::logger::warning(format!("File '{}' is not of SVG type", path_in.clone().to_str().unwrap()))), + }; + if ext.to_str().unwrap() != "svg" { + return Err(util::logger::warning(format!("File '{}' is not of SVG type", path_in.clone().to_str().unwrap()))); } let svg_data = match std::fs::read_to_string(path_in.clone()) { @@ -88,7 +92,7 @@ impl Renderer { //fill="currentColor" let mut tree = match usvg::Tree::from_data(&svg_data_bytes, &opt) { Ok(v) => Ok(v), - Err(_) => Err(util::logger::error(format!("Failed to parse '{}'", path_in.display()))) + Err(_) => Err(util::logger::error(format!("Failed to parse '{}'", path_in.clone().display()))) }?; tree.convert_text(&self.fontdb);