helpers: fix absolutePath relative with tilde (#640)

Relative path was not handled if input started with tilde.
Examples:
	~/./test
	~/weird/../test

No reason to do something like this imho, but users you never know.
This commit is contained in:
davc0n 2025-01-06 14:18:13 +01:00 committed by GitHub
parent 00d2cbfee3
commit de844d39ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,6 @@
#include <algorithm>
#include <cmath>
#include "MiscFunctions.hpp"
#include "../helpers/Log.hpp"
#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
@ -13,10 +12,11 @@ std::string absolutePath(const std::string& rawpath, const std::string& currentD
// Handling where rawpath starts with '~'
if (!rawpath.empty() && rawpath[0] == '~') {
static const char* const ENVHOME = getenv("HOME");
return std::filesystem::path(ENVHOME) / path.relative_path().string().substr(2);
path = std::filesystem::path(ENVHOME) / path.relative_path().string().substr(2);
}
// Handling e.g. ./, ../
else if (path.is_relative()) {
if (path.is_relative()) {
return std::filesystem::weakly_canonical(std::filesystem::path(currentDir) / path);
} else {
return std::filesystem::weakly_canonical(path);