Path util: BLI_path_contains() case-insensitive on Windows

Make `BLI_path_contains()` case-insensitive on Windows. This behaviour
is dependent on the platform Blender is running on, like the rest of
BLI_path, and not on the style of paths (Windows-style paths will be
treated case-sensitively when Blender is running on Linux/macOS).
This commit is contained in:
Sybren A. Stüvel 2021-09-28 11:05:45 +02:00
parent 741fa8180c
commit b91946780c
2 changed files with 13 additions and 0 deletions

View File

@ -1951,6 +1951,11 @@ bool BLI_path_contains(const char *container_path, const char *containee_path)
BLI_path_normalize(NULL, container_native);
BLI_path_normalize(NULL, containee_native);
#ifdef WIN32
BLI_str_tolower_ascii(container_native, PATH_MAX);
BLI_str_tolower_ascii(containee_native, PATH_MAX);
#endif
if (STREQ(container_native, containee_native)) {
/* The paths are equal, they contain each other. */
return true;

View File

@ -678,3 +678,11 @@ TEST(path_util, PathContains)
EXPECT_FALSE(BLI_path_contains("/some/path", "./contents"))
<< "Relative paths are not supported";
}
#ifdef WIN32
TEST(path_util, PathContains_Windows_case_insensitive)
{
EXPECT_TRUE(BLI_path_contains("C:\\some\\path", "c:\\SOME\\path\\inside"))
<< "On Windows path comparison should ignore case";
}
#endif