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

Handle the situation when GRAV_ROOT or GRAV_WEBROOT are / #3667

Merged
merged 5 commits into from
Apr 16, 2024

Conversation

thebodzio
Copy link
Contributor

I am using a hosting service which separates the site files in such a way that both GRAV_ROOT and GRAV_WEBROOT are /. Unfortunately, this tends to break some of the Grav and plugin's functionality—most importantly backups and upgrades (in grav-plugin-admin).

This is caused by the use of rtrim to remove trailing slashes from path names. When GRAV_ROOT or GRAV_WEBROOT are / this effectively sets both to an empty string, which, in turn, makes the aforementioned scenarios to fail miserably.

The fix is very simple. Whenever GRAV_ROOT or GRAV_WEBROOT are to be evaluated to an empty string (it can only happen if their paths contain only / characters), they are arbitrarily set to /.

@thebodzio thebodzio changed the title Handle the situation when GRAV_ROOT or GARV_WEBROOT are / Handle the situation when GRAV_ROOT or GRAV_WEBROOT are / Dec 28, 2022
@AnaelMobilia
Copy link
Contributor

@thebodzio ,
In order to be compatible with Windows, you should maybe use DIRECTORY_SEPARATOR instead of /.
Best regards,
Anael

@thebodzio
Copy link
Contributor Author

thebodzio commented Mar 10, 2023

@AnaelMobilia,

Thanks for the suggestion, however, I don't think this will ever be an issue. First, I don't think we will have a Windows path starting with /—that is unless some specific “mapping” will be done by this or that piece of software in order to “hide” drive letters. Second, it would be counterproductive, since one line before all DIRECTORY_SEPARATORs were intentionally replaced with DSs (speaking about defines.php).

That being said, I do agree that it would be much more elegant to consistently use DS since it was pretty much globally defined for the whole Grav. I will modify my commit accordingly.

Have a great day!

Replaced `/` with `DS`
Replaced `/` with `DS` in `backup` function
@thebodzio
Copy link
Contributor Author

Corrections have been made. Awaiting your kind consideration 👍😊

@rhukster rhukster merged commit d184e25 into getgrav:develop Apr 16, 2024
@thebodzio thebodzio deleted the grav-root branch April 16, 2024 18:21
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 this pull request may close these issues.

3 participants