Fix trailing slashes causing normalized path comparison to fail

This commit is contained in:
Campbell Barton
2023-05-17 12:57:59 +10:00
parent f1d436a3aa
commit 0ae286be03
2 changed files with 24 additions and 0 deletions

View File

@@ -1947,6 +1947,10 @@ int BLI_path_cmp_normalized(const char *p1, const char *p2)
BLI_path_slash_native(norm_p1);
BLI_path_slash_native(norm_p2);
/* One of the paths ending with a slash does not make them different, strip both. */
BLI_path_slash_rstrip(norm_p1);
BLI_path_slash_rstrip(norm_p2);
BLI_path_normalize(norm_p1);
BLI_path_normalize(norm_p2);

View File

@@ -155,6 +155,26 @@ TEST(path_util, Normalize_UnbalancedRelativeTrailing)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Tests for: #BLI_path_cmp_normalized
*
* \note #BLI_path_normalize tests handle most of the corner cases.
* \{ */
TEST(path_util, CompareNormalized)
{
/* Trailing slash should not matter. */
EXPECT_EQ(BLI_path_cmp_normalized("/tmp/", "/tmp"), 0);
/* Slash direction should not matter. */
EXPECT_EQ(BLI_path_cmp_normalized("\\tmp\\", "/tmp/"), 0);
/* Empty paths should be supported. */
EXPECT_EQ(BLI_path_cmp_normalized("", ""), 0);
EXPECT_NE(BLI_path_cmp_normalized("A", "B"), 0);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Tests for: #BLI_path_parent_dir
* \{ */