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

fix: std::filesystem::equivalent does not work for non-exist path #2186

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion engine/e2e-test/api/files/test_api_create_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def setup_and_teardown(self):
# Teardown
stop_server()

@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window")
def test_api_create_file_successfully(self):
# Define file path
file_path_rel = os.path.join("e2e-test", "api", "files", "blank.txt")
Expand Down
10 changes: 3 additions & 7 deletions engine/repositories/file_fs_repository.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ std::filesystem::path SanitizePath(const std::filesystem::path& user_input,
std::filesystem::path resolved_path = std::filesystem::weakly_canonical(
std::filesystem::path(basedir) / std::filesystem::path(user_input));
/* Ensure the resolved path is within our basedir */
for (auto p = resolved_path; !p.empty(); p = p.parent_path()) {
if (std::filesystem::equivalent(p, abs_base)) {
return resolved_path;
}
if (p == p.parent_path()) { // reached the root directory
break;
}
if (resolved_path.string().find(abs_base.string()) != std::string::npos) {
return resolved_path;
}

return {};
}

Expand Down
Loading