Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit fdc0745

Browse files
committed
fix: std::filesystem::equivalent does not work for non-exist path
1 parent ae43c53 commit fdc0745

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

engine/repositories/file_fs_repository.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ std::filesystem::path SanitizePath(const std::filesystem::path& user_input,
1818
std::filesystem::path resolved_path = std::filesystem::weakly_canonical(
1919
std::filesystem::path(basedir) / std::filesystem::path(user_input));
2020
/* Ensure the resolved path is within our basedir */
21-
for (auto p = resolved_path; !p.empty(); p = p.parent_path()) {
22-
if (std::filesystem::equivalent(p, abs_base)) {
23-
return resolved_path;
24-
}
25-
if (p == p.parent_path()) { // reached the root directory
26-
break;
27-
}
21+
if (resolved_path.string().find(abs_base.string()) != std::string::npos) {
22+
return resolved_path;
2823
}
24+
2925
return {};
3026
}
3127

0 commit comments

Comments
 (0)