Skip to content

Commit 552db8f

Browse files
fix: std::filesystem::equivalent does not work for non-exist path (#2182)
* fix: std::filesystem::equivalent does not work for non-exist path * chore: enable create file test for all platforms (#2183) --------- Co-authored-by: sangjanai <[email protected]>
1 parent 5c6066c commit 552db8f

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

engine/e2e-test/api/files/test_api_create_file.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def setup_and_teardown(self):
2323
# Teardown
2424
stop_server()
2525

26-
@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window")
2726
def test_api_create_file_successfully(self):
2827
# Define file path
2928
file_path_rel = os.path.join("e2e-test", "api", "files", "blank.txt")

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)