Skip to content

Commit

Permalink
helpers: fix absolutePath relative with tilde (hyprwm#640)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davc0n authored and vaxerski committed Jan 23, 2025
1 parent 77e4a05 commit 71cada2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/helpers/MiscFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <algorithm>
#include <cmath>
#include "MiscFunctions.hpp"
#include "../helpers/Log.hpp"
#include <hyprutils/string/String.hpp>

using namespace Hyprutils::String;
Expand All @@ -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);
Expand Down

0 comments on commit 71cada2

Please sign in to comment.