Skip to content

Commit

Permalink
derive: don't panic if the extension is non-UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Aug 7, 2024
1 parent 1ff32cb commit 8b08bcf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rinja_derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,12 @@ fn ext_default_to_path<'a>(ext: Option<&'a str>, path: &'a Path) -> Option<&'a s
fn extension(path: &Path) -> Option<&str> {
const JINJA_EXTENSIONS: &[&str] = &["j2", "jinja", "jinja2", "rinja"];

let ext = path.extension().map(|s| s.to_str().unwrap())?;
let ext = path.extension()?.to_str()?;
if JINJA_EXTENSIONS.contains(&ext) {
// an extension was found: file stem cannot be absent
Path::new(path.file_stem().unwrap())
.extension()
.map(|s| s.to_str().unwrap())
.and_then(|s| s.to_str())
.or(Some(ext))
} else {
Some(ext)
Expand Down

0 comments on commit 8b08bcf

Please sign in to comment.