Fix trailing slashes causing normalized path comparison to fail
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
* \{ */
|
||||
|
||||
Reference in New Issue
Block a user