Skip to content

Commit

Permalink
Fixed crash when file has no extension
Browse files Browse the repository at this point in the history
  • Loading branch information
MCorange99 committed Feb 17, 2023
1 parent 0f8cf83 commit e93556a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
12 changes: 8 additions & 4 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit e93556a

Please sign in to comment.