Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits 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