From de844d39adb09a827f15f4246a10bb7876f3c341 Mon Sep 17 00:00:00 2001 From: davc0n Date: Mon, 6 Jan 2025 14:18:13 +0100 Subject: [PATCH] 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. --- src/helpers/MiscFunctions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index b581dec..2add0ed 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -2,7 +2,6 @@ #include #include #include "MiscFunctions.hpp" -#include "../helpers/Log.hpp" #include 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);