Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) path trail slash check on Windows #405

Merged
merged 2 commits into from Dec 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/registry.rs
Expand Up @@ -272,7 +272,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
Expand Down Expand Up @@ -718,6 +722,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, "<h1>Bonjour {{world}}!</h1>").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]
Expand Down