Skip to content

Commit ef50164

Browse files
committed
Fix test directory creation by normalizing paths
Added path normalization using std::filesystem::path::lexically_normal() to resolve '..' components before attempting directory creation.
1 parent b51e059 commit ef50164

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/RenderingFramework/OpenGLTestContext.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,25 @@ namespace TestHelpers
4343
// Recursive helper function to create a directory tree.
4444
void createDirectoryTree(const std::filesystem::path& directoryTree)
4545
{
46+
// Normalize the path to resolve any ".." components
47+
std::filesystem::path normalizedPath = directoryTree.lexically_normal();
48+
4649
// Nothing to do, end recursion.
47-
if (std::filesystem::exists(directoryTree))
50+
if (std::filesystem::exists(normalizedPath))
4851
{
4952
return;
5053
}
5154

5255
// Make sure the parent directory exists.
5356
// Note: std::filesystem::create_directory can only create the leaf of the directory tree,
5457
// hence the recursion.
55-
createDirectoryTree(directoryTree.parent_path());
58+
createDirectoryTree(normalizedPath.parent_path());
5659

5760
// Create the final directory.
58-
if (!std::filesystem::create_directory(directoryTree))
61+
if (!std::filesystem::create_directory(normalizedPath))
5962
{
6063
throw std::runtime_error(
61-
std::string("Failed to create the directory: ") + directoryTree.string());
64+
std::string("Failed to create the directory: ") + normalizedPath.string());
6265
}
6366
}
6467

0 commit comments

Comments
 (0)