mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 13:30:59 +00:00
derive: don't panic if the extension is non-UTF-8
This commit is contained in:
parent
1ff32cb0ab
commit
ed692a087d
@ -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> {
|
fn extension(path: &Path) -> Option<&str> {
|
||||||
const JINJA_EXTENSIONS: &[&str] = &["j2", "jinja", "jinja2", "rinja"];
|
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) {
|
if JINJA_EXTENSIONS.contains(&ext) {
|
||||||
|
// an extension was found: file stem cannot be absent
|
||||||
Path::new(path.file_stem().unwrap())
|
Path::new(path.file_stem().unwrap())
|
||||||
.extension()
|
.extension()
|
||||||
.map(|s| s.to_str().unwrap())
|
.and_then(|s| s.to_str())
|
||||||
.or(Some(ext))
|
.or(Some(ext))
|
||||||
} else {
|
} else {
|
||||||
Some(ext)
|
Some(ext)
|
||||||
|
@ -1 +1 @@
|
|||||||
foo.html.rinja
|
foo.html.rinja
|
@ -1 +1 @@
|
|||||||
foo.rinja
|
foo.rinja
|
Loading…
x
Reference in New Issue
Block a user