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

Canonicalize include paths before emitting #258

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rinja_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ impl<'a> Generator<'a> {
Source::Source(_) => path != &*self.input.path,
};
if path_is_valid {
let path = path.to_str().unwrap();
buf.write(format_args!(
"const _: &[rinja::helpers::core::primitive::u8] =\
rinja::helpers::core::include_bytes!({path:#?});",
rinja::helpers::core::include_bytes!({:#?});",
path.canonicalize().as_deref().unwrap_or(path),
));
}
}
Expand Down
6 changes: 3 additions & 3 deletions rinja_derive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ fn check_if_let() {

// In this test we make sure that every used template gets referenced exactly once.
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("templates");
let path1 = path.join("include1.html");
let path2 = path.join("include2.html");
let path3 = path.join("include3.html");
let path1 = path.join("include1.html").canonicalize().unwrap();
let path2 = path.join("include2.html").canonicalize().unwrap();
let path3 = path.join("include3.html").canonicalize().unwrap();
compare(
r#"{% include "include1.html" %}"#,
&format!(
Expand Down