44 const std::filesystem::path& candidate) {
45 const auto root = directory.lexically_normal();
46 const auto path = candidate.lexically_normal();
53 if (path.has_root_name() || path.has_root_directory())
55 return path.empty() || *path.begin() !=
"..";
57 auto r = root.begin();
58 auto p = path.begin();
59 for (; r != root.end(); ++r) {
62 if (r->empty() && std::next(r) == root.end())
64 if (p == path.end() || *p != *r)
bool is_safe_relative_path(const std::filesystem::path &path)
True only if path is safe to join beneath a destination directory: a non-empty relative path with no ...
Definition safe_relative_path.hpp:25
bool is_within_directory(const std::filesystem::path &directory, const std::filesystem::path &candidate)
True if candidate, compared lexically after normalization, is directory itself or lies beneath it.
Definition safe_relative_path.hpp:43