diff --git a/src/registry.rs b/src/registry.rs index 37b3b26fa..67530de7c 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -244,7 +244,11 @@ impl<'reg> Registry<'reg> { { let dir_path = dir_path.as_ref(); - let prefix_len = if dir_path.to_string_lossy().ends_with(path::MAIN_SEPARATOR) { + let prefix_len = if dir_path + .to_string_lossy() + .ends_with(|c| c == '\\' || c == '/') + // `/` will work on windows too so we still need to check + { dir_path.to_string_lossy().len() } else { dir_path.to_string_lossy().len() + 1 @@ -706,6 +710,29 @@ mod test { dir.close().unwrap(); } + + { + let dir = tempdir().unwrap(); + + let file1_path = dir.path().join("t10.hbs"); + let mut file1: File = File::create(&file1_path).unwrap(); + writeln!(file1, "

Bonjour {{world}}!

").unwrap(); + + let mut dir_path = dir + .path() + .to_string_lossy() + .replace(std::path::MAIN_SEPARATOR, "/"); + if !dir_path.ends_with("/") { + dir_path.push('/'); + } + r.register_templates_directory(".hbs", dir_path).unwrap(); + + assert_eq!(r.templates.len(), 8); + assert_eq!(r.templates.contains_key("t10"), true); + + drop(file1); + dir.close().unwrap(); + } } #[test]