mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-20 15:00:36 +00:00
fix: prevent IWD paths from matching nested filenames (#908)
Fixes https://github.com/Laupetin/OpenAssetTools/issues/887
This commit is contained in:
@@ -31,7 +31,7 @@ namespace
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
path = parentDir.string();
|
path = parentDir.string();
|
||||||
prefix = combinedPath.filename().string();
|
prefix = combinedPath.string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -77,7 +77,7 @@ void SearchPathFilesystem::Find(const SearchPathSearchOptions& options, const st
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto entryPath = entry->path();
|
auto entryPath = entry->path();
|
||||||
if (!prefix.empty() && !entryPath.filename().string().starts_with(prefix))
|
if (!prefix.empty() && !entryPath.string().starts_with(prefix))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (options.m_filter_extensions && entryPath.extension().string() != options.m_extension)
|
if (options.m_filter_extensions && entryPath.extension().string() != options.m_extension)
|
||||||
@@ -104,7 +104,7 @@ void SearchPathFilesystem::Find(const SearchPathSearchOptions& options, const st
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto entryPath = entry->path();
|
auto entryPath = entry->path();
|
||||||
if (!prefix.empty() && !entryPath.filename().string().starts_with(prefix))
|
if (!prefix.empty() && !entryPath.string().starts_with(prefix))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (options.m_filter_extensions && entryPath.extension().string() != options.m_extension)
|
if (options.m_filter_extensions && entryPath.extension().string() != options.m_extension)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include "OatTestPaths.h"
|
||||||
|
#include "SearchPath/SearchPathFilesystem.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
TEST_CASE("SearchPathFilesystem: Does not match a nested filename against a path prefix", "[searchpath]")
|
||||||
|
{
|
||||||
|
const auto searchPathRoot = oat::paths::GetTempDirectory("SearchPathFilesystem");
|
||||||
|
const auto unrelatedFile = searchPathRoot / "iwd" / "maps" / "mp" / "mod.txt";
|
||||||
|
fs::create_directories(unrelatedFile.parent_path());
|
||||||
|
std::ofstream(unrelatedFile) << "test";
|
||||||
|
|
||||||
|
SearchPathFilesystem searchPath(searchPathRoot.string());
|
||||||
|
std::vector<std::string> results;
|
||||||
|
searchPath.Find(SearchPathSearchOptions().FilterPrefix("iwd/mod").IncludeSubdirectories(true),
|
||||||
|
[&results](const std::string& path)
|
||||||
|
{
|
||||||
|
results.emplace_back(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
REQUIRE(results.empty());
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
Reference in New Issue
Block a user