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

globwalk does not work with several relative paths #574

Closed
FibreFoX opened this issue Nov 14, 2020 · 15 comments · Fixed by #799
Closed

globwalk does not work with several relative paths #574

FibreFoX opened this issue Nov 14, 2020 · 15 comments · Fixed by #799

Comments

@FibreFoX
Copy link

While migrating from a NodeJS-based project to a Rust-based project I found Tera as a template-engine, it was ment to be my introduction project to learn Rust.

As I separate my program and the used templates, I wanted to pass a relative path of some upper folder, but Tera did not find them. After some investigation (and local experiments to change globwalk with glob, which did not work due to unsupported syntax having curly-braces "examples/basic/templates/**/*.{html, xml}"), I found out that it only is an issue for path that point to the current or upper-level folders.

Globwalk does not work for paths starting with./ or ../, there is already an issue open at the other project: Gilnaa/globwalk#28

@Keats
Copy link
Owner

Keats commented Nov 14, 2020

So it should be fixed upstream then

@FibreFoX
Copy link
Author

At least there, but until then I think it's worth to get mentioned somewhere, that's why I opened this issue here. Others might wonder too.

@eguiraud
Copy link
Contributor

Hi, due to Gilnaa/globwalk#28 mentioned above passing a path starting with ./ or ../ to Tera::new is completely broken. It does not look like Gilnaa/globwalk#28 is going to be fixed any time soon (it's been 2 years already and there is no consensus on the direction to take).

Could Tera maybe side-step the issue by switching to glob or globset?

In my project I'm working around this by taking care to normalize the path I pass to Tera::new, but if there is a clear direction for a fix I could maybe contribute it.

@Keats
Copy link
Owner

Keats commented Jan 21, 2023

Could Tera maybe side-step the issue by switching to glob or globset?

If we can make it work without breaking any existing code, sure.

@eguiraud
Copy link
Contributor

without breaking any existing code

I am not sure how to guarantee that (I am not sure globwalk and globset behave identically for all inputs).

Something simpler to check would be that the change doesn't break any existing test 😅

@caemor
Copy link

caemor commented Jan 22, 2023

Alternatively we could check if the input starts with ./ or ../ and return an error instead of an empty list and document this for the Tera::new command.

This wouldn't really fix the issue, but at least make it more visible why tera doesn't work as expected for this usecase.

@Keats
Copy link
Owner

Keats commented Jan 22, 2023

That would still be a breaking change though.
If someone can do a PR we can test things.

@eguiraud
Copy link
Contributor

we could check if the input starts with ./ or ../ and return an error

That would still be a breaking change though.

Only for users that expect that adding a ./ at the beginning of the path always results in an empty list. I'm not sure why you would want to keep those weirdos happy... 😄

If someone can do a PR we can test things.

It should be easy enough to have Tera detect this case and error out, I'll try to propose a PR soon. Too bad there is no clear path to an actual resolution.

@Keats
Copy link
Owner

Keats commented Jan 24, 2023

I'm not sure why you would want to keep those weirdos happy... 😄

https://xkcd.com/1172/

@eguiraud
Copy link
Contributor

I'm perfectly sure those weirdos exist (hyrum's law and all that) 😄 but you don't necessarily have to keep them happy :P

@Keats
Copy link
Owner

Keats commented Jan 24, 2023

Yeah it's probably fine if it always returned an empty list of files tbh

eguiraud added a commit to eguiraud/tera that referenced this issue Jan 24, 2023
This is because globwalk always returns an empty list in that
case, which is likely not what users expect.

The corresponding issue in globwalk is
Gilnaa/globwalk#28.

See Keats#574 for more discussion.
@eguiraud
Copy link
Contributor

eguiraud commented Jan 24, 2023

A PR that makes Tera::new error out is up. Locally it produced no test failures.

For the record I still think that doing what 99.9% of users would expect out of the box (i.e. treating ./some/dir/*.html the same as /path/to/some/dir/*.html) would be better, but I guess that's a bigger change in behavior.

@FibreFoX
Copy link
Author

Not sure that I am happy with Tera reporting errors with relative paths like in that PR. It does not fix the problem, it just makes more noise.
In my opinion it would be a better fix to use something different than globwalk (and yes, breaking changes are okay IMHO if they introduce fixes).

@Keats
Copy link
Owner

Keats commented Jan 26, 2023

Can we do a PR with a fix as well?

eguiraud added a commit to eguiraud/tera that referenced this issue Jan 26, 2023
This is a regression test for Keats#574.
eguiraud added a commit to eguiraud/tera that referenced this issue Jan 26, 2023
This is to work around an issue in globwalk
(Gilnaa/globwalk#28) due to which paths
starting with `./` or `../` never match anything.

This fixes Keats#574.
@eguiraud
Copy link
Contributor

I agree with you @FibreFoX , I just thought there was no consensus on what an actual fix should/would look like, so in the meanwhile I'd rather have Tera report the issue rather than silently having a surprising behavior.

@Keats a PR with what I would propose as an actual fix is at #799 .

eguiraud added a commit to eguiraud/tera that referenced this issue Jan 26, 2023
This is to work around an issue in globwalk
(Gilnaa/globwalk#28) due to which paths
starting with `./` or `../` never match anything.

This fixes Keats#574.
@Keats Keats closed this as completed in #799 Mar 8, 2023
Keats pushed a commit that referenced this issue Mar 8, 2023
* Add test for globs starting with "./"

This is a regression test for #574.

* Always canonicalize glob paths passed to Tera

This is to work around an issue in globwalk
(Gilnaa/globwalk#28) due to which paths
starting with `./` or `../` never match anything.

This fixes #574.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants