Switch to std::path::absolute to avoid symlinking template paths#720
Switch to std::path::absolute to avoid symlinking template paths#720GuillaumeGomez merged 6 commits intoaskama-rs:mainfrom
std::path::absolute to avoid symlinking template paths#720Conversation
|
I think it's the correct fix, although for the error display, would be better to keep the original path. Or eventually the original followed by the absolute path in parens. |
b3c93f1 to
e203eaa
Compare
- Add a test to verify symlink behavior - Update existing tests to reflect new error message All tests passes ```shell TRYBUILD=overwrite RUSTUP_TOOLCHAIN=stable cargo nextest run --features full ```
e203eaa to
f3c1b0d
Compare
|
Added changes to reflect path names for the other tests, and added a new test case to test the symlink behavior. |
| error: cyclic dependency in graph [ | ||
| "\"$DIR/templates/cycle2.html/" --> \"$DIR/templates/cycle1.html/"", | ||
| "\"$DIR/templates/cycle1.html/" --> \"$DIR/templates/cycle1.html/"", | ||
| "\"$WORKSPACE/target/tests/trybuild/askama_testing/templates/cycle2.html/" --> \"$WORKSPACE/target/tests/trybuild/askama_testing/templates/cycle1.html/"", |
There was a problem hiding this comment.
That's not what I meant in my comment.
There was a problem hiding this comment.
Reverted changes to the test files. My bad.
There was a problem hiding this comment.
I think it's the correct fix, although for the error display, would be better to keep the original path. Or eventually the original followed by the absolute path in parens.
I should be more precise. This test output will need to be updated, however we need to make it clear to the users why this cycle error occurred. What I had in mind was something like:
cyclic dependency in graph [
"$DIR/cycle2.html" (absolute path: "$WORKSPACE/target/tests/trybuild/askama_testing/templates/cycle2.html") --> "$DIR/templates/cycle1.html/" (absolute path: "$WORKSPACE/target/tests/trybuild/askama_testing/templates/cycle1.html")
...
]
So the original path followed by the absolute path in parens.
There was a problem hiding this comment.
Ah got it now. It might require to keep both original and absolute path values from the find_templates's return type, or make some adjustments in the input.rs file so that the error message constructors have both the paths.
Will share the commit for this soon.
There was a problem hiding this comment.
Have updated the error messages in the latest commit.
01d40da to
a08118c
Compare
Showing both paths requires storing the original path. It needs to be threaded through to the error constructor functions. Regenerated tests/ui files with ```shell TRYBUILD=overwrite RUSTUP_TOOLCHAIN=stable cargo nextest run --features full ```
GuillaumeGomez
left a comment
There was a problem hiding this comment.
Apart from the nits, looks all good!
Orig(inal) reflects usage better. Updated all usages.
|
Ah right, windows gonna be an issue (as usual). |
|
Figuring that out, I am expecting running things with --target as windows should allow me to replicate it. Given that we have changed path resolution logic itself, the solution should most likely be updating the tests cases ? Will try things locally and update. |
|
It seems I can't test things locally as Windows. I only have a Mac. Tried out different ways but didn't work out. Updated the tests to use |
|
Different failure this time: But at least your fix for the paths display worked, well done! |
Not having an extension is important for the testcase. Override line endings manually. It's already done been done for all .html and .txt files. This should satisfy windows tests.
|
|
|
Code looks good, CI is happy. Time to merge. Thanks a lot! |
|
Thanks a lot for the reviews ! |
In our build system, we use content addressable storage, where the template files lose their extensions. For e.g. for the below
Which might become a file such as
As we have lost the extension, it defaults to empty strings here. So instead of applying the default HTML filter to escape symbols, it defaults to
None.The fix suggested switches to
absolute, which avoids symlinking the template path. This preserves the file extension and the correct escaper is applied.I am seeing other issues such as #288, #708 which also revolve around absolute / canonical paths. All the tests do pass with this change, but there are other workarounds to preserve the file path, which can possibly avoid affecting their systems.
For e.g. storing the file extension before passing
config.find_templatein theTemplateInput::new.